@@ -20,6 +20,7 @@ import (
2020 "compress/gzip"
2121 "fmt"
2222 "os"
23+ "strings"
2324 "testing"
2425 "time"
2526
@@ -82,6 +83,113 @@ func TestNewMissedUrl(t *testing.T) {
8283 }
8384}
8485
86+ //splunk-url needs to be in the format of scheme://dns_name_or_ip<:port>
87+ func TestUrlFormat (t * testing.T ) {
88+ info := logger.Info {
89+ Config : map [string ]string {
90+ splunkURLKey : "127.0.0.1" ,
91+ },
92+ }
93+ _ , err := parseURL (info )
94+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
95+ t .Fatal ("Logger driver should fail when no schema is specified" )
96+ }
97+
98+ info = logger.Info {
99+ Config : map [string ]string {
100+ splunkURLKey : "www.google.com" ,
101+ },
102+ }
103+ _ , err = parseURL (info )
104+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
105+ t .Fatal ("Logger driver should fail when schema is not specified" )
106+ }
107+
108+ info = logger.Info {
109+ Config : map [string ]string {
110+ splunkURLKey : "ftp://127.0.0.1" ,
111+ },
112+ }
113+ _ , err = parseURL (info )
114+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
115+ t .Fatal ("Logger driver should fail when schema is not http or https" )
116+ }
117+
118+ info = logger.Info {
119+ Config : map [string ]string {
120+ splunkURLKey : "http://127.0.0.1:8088/test" ,
121+ },
122+ }
123+ _ , err = parseURL (info )
124+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
125+ t .Fatal ("Logger driver should fail when path is specified" )
126+ }
127+
128+ info = logger.Info {
129+ Config : map [string ]string {
130+ splunkURLKey : "testURL" ,
131+ },
132+ }
133+ _ , err = parseURL (info )
134+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
135+ t .Fatal ("Logger driver should fail when no schema is specified" )
136+ }
137+
138+ info = logger.Info {
139+ Config : map [string ]string {
140+ splunkURLKey : "http://www.host.com/?q=hello" ,
141+ },
142+ }
143+ _ , err = parseURL (info )
144+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
145+ t .Fatal ("Logger driver should fail when query parameter is specified" )
146+ }
147+
148+ info = logger.Info {
149+ Config : map [string ]string {
150+ splunkURLKey : "http://www.host.com#hello" ,
151+ },
152+ }
153+ _ , err = parseURL (info )
154+ if err .Error () != "splunk: expected format scheme://dns_name_or_ip:port for splunk-url" {
155+ t .Fatal ("Logger driver should fail when fragment is specified" )
156+ }
157+
158+ info = logger.Info {
159+ Config : map [string ]string {
160+ splunkURLKey : "127.0.1:8000" ,
161+ },
162+ }
163+ _ , err = parseURL (info )
164+ if ! strings .HasPrefix (err .Error (), "splunk: failed to parse" ) {
165+ t .Fatal ("Logger driver should fail when path is specified" )
166+ }
167+
168+ info = logger.Info {
169+ Config : map [string ]string {
170+ splunkURLKey : "https://127.0.1:8000" ,
171+ },
172+ }
173+
174+ url , err := parseURL (info )
175+
176+ if url .String () != "https://127.0.1:8000/services/collector/event/1.0" {
177+ t .Fatalf ("%s is not the right format of HEC endpoint." , url .String ())
178+ }
179+
180+ info = logger.Info {
181+ Config : map [string ]string {
182+ splunkURLKey : "https://127.0.1:8000/" ,
183+ },
184+ }
185+
186+ url , err = parseURL (info )
187+
188+ if url .String () != "https://127.0.1:8000/services/collector/event/1.0" {
189+ t .Fatalf ("%s is not the right format of HEC endpoint." , url .String ())
190+ }
191+ }
192+
85193// Driver require user to specify splunk-token
86194func TestNewMissedToken (t * testing.T ) {
87195 info := logger.Info {
@@ -126,8 +234,8 @@ func TestDefault(t *testing.T) {
126234 t .Fatal ("Unexpected logger driver name" )
127235 }
128236
129- if ! hec .connectionVerified {
130- t .Fatal ("By default connection should be verified" )
237+ if hec .connectionVerified {
238+ t .Fatal ("By default connection should not be verified" )
131239 }
132240
133241 splunkLoggerDriver , ok := loggerDriver .(* splunkLoggerInline )
@@ -1088,7 +1196,7 @@ func TestSkipVerify(t *testing.T) {
10881196 }
10891197
10901198 if len (hec .messages ) != defaultStreamChannelSize * 4 {
1091- t .Fatal ("Not all messages delivered" )
1199+ t .Fatal ("Not all messages delivered %s " )
10921200 }
10931201
10941202 for i , message := range hec .messages {
0 commit comments