@@ -78,18 +78,18 @@ func Test_newNodeLogQuery(t *testing.T) {
7878 want * nodeLogQuery
7979 wantErr bool
8080 }{
81- {name : "empty" , query : url.Values {}, want : nil },
82- {query : url.Values {"unknown" : []string {"true" }}, want : nil },
81+ {name : "empty" , query : url.Values {}, want : & nodeLogQuery {} },
82+ {query : url.Values {"unknown" : []string {"true" }}, want : & nodeLogQuery {} },
8383
84- {query : url.Values {"sinceTime" : []string {"" }}, want : nil },
84+ {query : url.Values {"sinceTime" : []string {"" }}, want : & nodeLogQuery {} },
8585 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00:00" }}, wantErr : true },
8686 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00:00.000" }}, wantErr : true },
8787 {query : url.Values {"sinceTime" : []string {"2019-12-04 02" }}, wantErr : true },
8888 {query : url.Values {"sinceTime" : []string {"2019-12-04 02:00" }}, wantErr : true },
8989 {query : url.Values {"sinceTime" : []string {validTimeValue }},
9090 want : & nodeLogQuery {options : options {SinceTime : & validT }}},
9191
92- {query : url.Values {"untilTime" : []string {"" }}, want : nil },
92+ {query : url.Values {"untilTime" : []string {"" }}, want : & nodeLogQuery {} },
9393 {query : url.Values {"untilTime" : []string {"2019-12-04 02:00:00" }}, wantErr : true },
9494 {query : url.Values {"untilTime" : []string {"2019-12-04 02:00:00.000" }}, wantErr : true },
9595 {query : url.Values {"untilTime" : []string {"2019-12-04 02" }}, wantErr : true },
@@ -103,7 +103,6 @@ func Test_newNodeLogQuery(t *testing.T) {
103103
104104 {query : url.Values {"pattern" : []string {"foo" }}, want : & nodeLogQuery {options : options {Pattern : "foo" }}},
105105
106- {query : url.Values {"boot" : []string {"" }}, want : nil },
107106 {query : url.Values {"boot" : []string {"0" }}, want : & nodeLogQuery {options : options {Boot : ptr .To (0 )}}},
108107 {query : url.Values {"boot" : []string {"-23" }}, want : & nodeLogQuery {options : options {Boot : ptr .To (- 23 )}}},
109108 {query : url.Values {"boot" : []string {"foo" }}, wantErr : true },
@@ -116,6 +115,11 @@ func Test_newNodeLogQuery(t *testing.T) {
116115 {query : url.Values {"query" : []string {"foo" , "/bar" }}, want : & nodeLogQuery {Services : []string {"foo" },
117116 Files : []string {"/bar" }}},
118117 {query : url.Values {"query" : []string {"/foo" , `\bar` }}, want : & nodeLogQuery {Files : []string {"/foo" , `\bar` }}},
118+ {query : url.Values {"unit" : []string {"" }}, wantErr : true },
119+ {query : url.Values {"unit" : []string {" " , " " }}, wantErr : true },
120+ {query : url.Values {"unit" : []string {"foo" }}, want : & nodeLogQuery {Services : []string {"foo" }}},
121+ {query : url.Values {"unit" : []string {"foo" , "bar" }}, want : & nodeLogQuery {Services : []string {"foo" , "bar" }}},
122+ {query : url.Values {"unit" : []string {"foo" , "/bar" }}, want : & nodeLogQuery {Services : []string {"foo" , "/bar" }}},
119123 }
120124 for _ , tt := range tests {
121125 t .Run (tt .query .Encode (), func (t * testing.T ) {
@@ -180,10 +184,12 @@ func Test_nodeLogQuery_validate(t *testing.T) {
180184 pattern = "foo"
181185 invalid = "foo\\ "
182186 )
183- since , err := time .Parse (time .RFC3339 , "2023-01-04T02:00:00Z" )
187+ sinceTime , err := time .Parse (time .RFC3339 , "2023-01-04T02:00:00Z" )
184188 assert .NoError (t , err )
185- until , err := time .Parse (time .RFC3339 , "2023-02-04T02:00:00Z" )
189+ untilTime , err := time .Parse (time .RFC3339 , "2023-02-04T02:00:00Z" )
186190 assert .NoError (t , err )
191+ since := "2019-12-04 02:00:00"
192+ until := "2019-12-04 03:00:00"
187193
188194 tests := []struct {
189195 name string
@@ -192,23 +198,37 @@ func Test_nodeLogQuery_validate(t *testing.T) {
192198 options options
193199 wantErr bool
194200 }{
195- {name : "empty" , wantErr : true },
196- {name : "empty with options" , options : options {SinceTime : & since }, wantErr : true },
201+ {name : "empty" },
202+ {name : "empty with options" , options : options {SinceTime : & sinceTime } },
197203 {name : "one service" , Services : []string {service1 }},
198204 {name : "two services" , Services : []string {service1 , service2 }},
199205 {name : "one service one file" , Services : []string {service1 }, Files : []string {file1 }, wantErr : true },
200206 {name : "two files" , Files : []string {file1 , file2 }, wantErr : true },
201207 {name : "one file options" , Files : []string {file1 }, options : options {Pattern : pattern }, wantErr : true },
202208 {name : "invalid pattern" , Services : []string {service1 }, options : options {Pattern : invalid }, wantErr : true },
203- {name : "since" , Services : []string {service1 }, options : options {SinceTime : & since }},
204- {name : "until" , Services : []string {service1 }, options : options {UntilTime : & until }},
205- {name : "since until" , Services : []string {service1 }, options : options {SinceTime : & until , UntilTime : & since },
206- wantErr : true },
207- // boot is not supported on Windows.
208- {name : "boot" , Services : []string {service1 }, options : options {Boot : ptr .To (- 1 )}, wantErr : runtime .GOOS == "windows" },
209+ {name : "sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime }},
210+ {name : "untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime }},
211+ {name : "sinceTime untilTime" , Services : []string {service1 }, options : options {SinceTime : & untilTime ,
212+ UntilTime : & sinceTime }, wantErr : true },
213+ {name : "boot" , Services : []string {service1 }, options : options {Boot : ptr .To (- 1 )}},
209214 {name : "boot out of range" , Services : []string {service1 }, options : options {Boot : ptr .To (1 )}, wantErr : true },
210215 {name : "tailLines" , Services : []string {service1 }, options : options {TailLines : ptr .To (100 )}},
211216 {name : "tailLines out of range" , Services : []string {service1 }, options : options {TailLines : ptr .To (100000 )}},
217+ {name : "since" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Since : since }}},
218+ {name : "since RFC3339" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Since : sinceTime .String ()}}, wantErr : true },
219+ {name : "until" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Until : until }}},
220+ {name : "until RFC3339" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Until : untilTime .String ()}}, wantErr : true },
221+ {name : "since sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime ,
222+ ocAdm : ocAdm {Since : since }}, wantErr : true },
223+ {name : "until sinceTime" , Services : []string {service1 }, options : options {SinceTime : & sinceTime ,
224+ ocAdm : ocAdm {Until : until }}, wantErr : true },
225+ {name : "since untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime ,
226+ ocAdm : ocAdm {Since : since }}, wantErr : true },
227+ {name : "until untilTime" , Services : []string {service1 }, options : options {UntilTime : & untilTime ,
228+ ocAdm : ocAdm {Until : until }}, wantErr : true },
229+ {name : "format" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Format : "cat" }}},
230+ {name : "format invalid" , Services : []string {service1 }, options : options {ocAdm : ocAdm {Format : "foo" }},
231+ wantErr : true },
212232 }
213233 for _ , tt := range tests {
214234 t .Run (tt .name , func (t * testing.T ) {
0 commit comments