@@ -73,18 +73,18 @@ func Test_newNodeLogQuery(t *testing.T) {
7373 want * nodeLogQuery
7474 wantErr bool
7575 }{
76- {name : "empty" , query : url.Values {}, want : nil },
77- {query : url.Values {"unknown" : []string {"true" }}, want : nil },
76+ {name : "empty" , query : url.Values {}, want : & nodeLogQuery {} },
77+ {query : url.Values {"unknown" : []string {"true" }}, want : & nodeLogQuery {} },
7878
79- {query : url.Values {"sinceTime" : []string {"" }}, want : nil },
79+ {query : url.Values {"sinceTime" : []string {"" }}, want : & nodeLogQuery {} },
8080 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00:00" }}, wantErr : true },
8181 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00:00.000" }}, wantErr : true },
8282 {query : url.Values {"sinceTime" : []string {"2019-12-04 02" }}, wantErr : true },
8383 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00" }}, wantErr : true },
8484 {query : url.Values {"sinceTime" : []string {validTimeValue }},
8585 want : & nodeLogQuery {options : options {SinceTime : & validT }}},
8686
87- {query : url.Values {"untilTime" : []string {"" }}, want : nil },
87+ {query : url.Values {"untilTime" : []string {"" }}, want : & nodeLogQuery {} },
8888 {query : url.Values {"untilTime" : []string {"2019-12-04 02:00:00" }}, wantErr : true },
8989 {query : url.Values {"untilTime" : []string {"2019-12-04 02:00:00.000" }}, wantErr : true },
9090 {query : url.Values {"untilTime" : []string {"2019-12-04 02" }}, wantErr : true },
@@ -98,7 +98,7 @@ func Test_newNodeLogQuery(t *testing.T) {
9898
9999 {query : url.Values {"pattern" : []string {"foo" }}, want : & nodeLogQuery {options : options {Pattern : "foo" }}},
100100
101- {query : url.Values {"boot" : []string {"" }}, want : nil },
101+ {query : url.Values {"boot" : []string {"" }}, want : & nodeLogQuery {} },
102102 {query : url.Values {"boot" : []string {"0" }}, want : & nodeLogQuery {options : options {Boot : intPtr (0 )}}},
103103 {query : url.Values {"boot" : []string {"-23" }}, want : & nodeLogQuery {options : options {Boot : intPtr (- 23 )}}},
104104 {query : url.Values {"boot" : []string {"foo" }}, wantErr : true },
@@ -111,6 +111,11 @@ func Test_newNodeLogQuery(t *testing.T) {
111111 {query : url.Values {"query" : []string {"foo" , "/bar" }}, want : & nodeLogQuery {Services : []string {"foo" },
112112 Files : []string {"/bar" }}},
113113 {query : url.Values {"query" : []string {"/foo" , `\bar` }}, want : & nodeLogQuery {Files : []string {"/foo" , `\bar` }}},
114+ {query : url.Values {"unit" : []string {"" }}, wantErr : true },
115+ {query : url.Values {"unit" : []string {" " , " " }}, wantErr : true },
116+ {query : url.Values {"unit" : []string {"foo" }}, want : & nodeLogQuery {Services : []string {"foo" }}},
117+ {query : url.Values {"unit" : []string {"foo" , "bar" }}, want : & nodeLogQuery {Services : []string {"foo" , "bar" }}},
118+ {query : url.Values {"unit" : []string {"foo" , "/bar" }}, want : & nodeLogQuery {Services : []string {"foo" , "/bar" }}},
114119 }
115120 for _ , tt := range tests {
116121 t .Run (tt .query .Encode (), func (t * testing.T ) {
@@ -173,10 +178,12 @@ func Test_nodeLogQuery_validate(t *testing.T) {
173178 pattern = "foo"
174179 invalid = "foo\\ "
175180 )
176- since , err := time .Parse (time .RFC3339 , "2023-01-04T02:00:00Z" )
181+ sinceTime , err := time .Parse (time .RFC3339 , "2023-01-04T02:00:00Z" )
177182 assert .NoError (t , err )
178- until , err := time .Parse (time .RFC3339 , "2023-02-04T02:00:00Z" )
183+ untilTime , err := time .Parse (time .RFC3339 , "2023-02-04T02:00:00Z" )
179184 assert .NoError (t , err )
185+ since := "2019-12-04 02:00:00"
186+ until := "2019-12-04 03:00:00"
180187
181188 tests := []struct {
182189 name string
@@ -185,23 +192,37 @@ func Test_nodeLogQuery_validate(t *testing.T) {
185192 options options
186193 wantErr bool
187194 }{
188- {name : "empty" , wantErr : true },
189- {name : "empty with options" , options : options {SinceTime : & since }, wantErr : true },
195+ {name : "empty" },
196+ {name : "empty with options" , options : options {SinceTime : & sinceTime } },
190197 {name : "one service" , Services : []string {service1 }},
191198 {name : "two services" , Services : []string {service1 , service2 }},
192199 {name : "one service one file" , Services : []string {service1 }, Files : []string {file1 }, wantErr : true },
193200 {name : "two files" , Files : []string {file1 , file2 }, wantErr : true },
194201 {name : "one file options" , Files : []string {file1 }, options : options {Pattern : pattern }, wantErr : true },
195202 {name : "invalid pattern" , Services : []string {service1 }, options : options {Pattern : invalid }, wantErr : true },
196- {name : "since" , Services : []string {service1 }, options : options {SinceTime : & since }},
197- {name : "until" , Services : []string {service1 }, options : options {UntilTime : & until }},
198- {name : "since until" , Services : []string {service1 }, options : options {SinceTime : & until , UntilTime : & since },
199- wantErr : true },
200- // boot is not supported on Windows.
201- {name : "boot" , Services : []string {service1 }, options : options {Boot : intPtr (- 1 )}, wantErr : runtime .GOOS == "windows" },
203+ {name : "sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime }},
204+ {name : "untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime }},
205+ {name : "sinceTime untilTime" , Services : []string {service1 }, options : options {SinceTime : & untilTime ,
206+ UntilTime : & sinceTime }, wantErr : true },
207+ {name : "boot" , Services : []string {service1 }, options : options {Boot : intPtr (- 1 )}},
202208 {name : "boot out of range" , Services : []string {service1 }, options : options {Boot : intPtr (1 )}, wantErr : true },
203209 {name : "tailLines" , Services : []string {service1 }, options : options {TailLines : intPtr (100 )}},
204210 {name : "tailLines out of range" , Services : []string {service1 }, options : options {TailLines : intPtr (100000 )}},
211+ {name : "since" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Since : since }}},
212+ {name : "since RFC3339" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Since : sinceTime .String ()}}, wantErr : true },
213+ {name : "until" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Until : until }}},
214+ {name : "until RFC3339" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Until : untilTime .String ()}}, wantErr : true },
215+ {name : "since sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime ,
216+ ocAdm : ocAdm {Since : since }}, wantErr : true },
217+ {name : "until sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime ,
218+ ocAdm : ocAdm {Until : until }}, wantErr : true },
219+ {name : "since untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime ,
220+ ocAdm : ocAdm {Since : since }}, wantErr : true },
221+ {name : "until untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime ,
222+ ocAdm : ocAdm {Until : until }}, wantErr : true },
223+ {name : "format" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Format : "cat" }}},
224+ {name : "format invalid" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Format : "foo" }},
225+ wantErr : true },
205226 }
206227 for _ , tt := range tests {
207228 t .Run (tt .name , func (t * testing.T ) {
0 commit comments