@@ -22,15 +22,6 @@ func TestMonitQueryDiagnoseFlags(t *testing.T) {
2222 }
2323}
2424
25- func TestMonitQueryRowsFlags (t * testing.T ) {
26- cmd := newMonitQueryRowsCmd ()
27- for _ , name := range []string {"ds-type" , "ds-name" , "expr" , "args" } {
28- if cmd .Flags ().Lookup (name ) == nil {
29- t .Errorf ("flag --%s missing" , name )
30- }
31- }
32- }
33-
3425func TestMonitQueryDataFlags (t * testing.T ) {
3526 cmd := newMonitQueryDataCmd ()
3627 for _ , name := range []string {"ds-type" , "ds-name" , "expr" , "args" , "delay-seconds" } {
@@ -209,7 +200,7 @@ func TestMonitQueryDiagnoseInvalidTimeStart(t *testing.T) {
209200 }
210201}
211202
212- // --- monit-query rows -----------------------------------------------------
203+ // --- monit-query data -----------------------------------------------------
213204
214205func TestMonitQueryDataHappyPath (t * testing.T ) {
215206 saveAndResetGlobals (t )
@@ -309,96 +300,6 @@ func TestMonitQueryDataRequiredFlags(t *testing.T) {
309300 }
310301}
311302
312- func TestMonitQueryRowsHappyPath (t * testing.T ) {
313- saveAndResetGlobals (t )
314- stub := newGFStub (t )
315- // rows is a raw datasource passthrough: the response envelope "data" is a
316- // JSON array of QueryRow ({fields,values}) objects, decoded into
317- // QueryRowsResponse ([]QueryRow) and re-marshalled verbatim to the writer.
318- stub .data = []any {
319- map [string ]any {
320- "fields" : map [string ]any {"instance" : "node-1" },
321- "values" : map [string ]any {"__value__" : 1 },
322- },
323- }
324-
325- out , err := execCommand (
326- "monit-query" , "rows" ,
327- "--ds-type" , "prometheus" ,
328- "--ds-name" , "prom-prod" ,
329- "--expr" , "up" ,
330- "--args" , "step=15s" ,
331- "--args" , "tenant=acme" ,
332- )
333- if err != nil {
334- t .Fatalf ("unexpected error: %v" , err )
335- }
336- if stub .lastPath != "/monit/query/rows" {
337- t .Fatalf ("expected /monit/query/rows, got %q" , stub .lastPath )
338- }
339- body := stub .lastBody
340- if body ["ds_type" ] != "prometheus" || body ["ds_name" ] != "prom-prod" || body ["expr" ] != "up" {
341- t .Errorf ("unexpected rows input: %#v" , body )
342- }
343- args , _ := body ["args" ].(map [string ]any )
344- if args ["step" ] != "15s" || args ["tenant" ] != "acme" {
345- t .Errorf ("expected args step=15s tenant=acme, got %#v" , args )
346- }
347- // The rendered output is the re-marshalled row array (passthrough shape).
348- if ! strings .Contains (out , "node-1" ) || ! strings .Contains (out , "__value__" ) {
349- t .Errorf ("expected rendered rows to carry the datasource payload, got:\n %s" , out )
350- }
351- }
352-
353- func TestMonitQueryRowsRequiredFlags (t * testing.T ) {
354- cases := []struct {
355- name string
356- args []string
357- }{
358- {
359- name : "missing ds-type" ,
360- args : []string {
361- "monit-query" , "rows" ,
362- "--ds-name" , "prom-prod" ,
363- "--expr" , "up" ,
364- },
365- },
366- {
367- name : "missing ds-name" ,
368- args : []string {
369- "monit-query" , "rows" ,
370- "--ds-type" , "prometheus" ,
371- "--expr" , "up" ,
372- },
373- },
374- {
375- name : "missing expr" ,
376- args : []string {
377- "monit-query" , "rows" ,
378- "--ds-type" , "prometheus" ,
379- "--ds-name" , "prom-prod" ,
380- },
381- },
382- }
383- for _ , tc := range cases {
384- t .Run (tc .name , func (t * testing.T ) {
385- saveAndResetGlobals (t )
386- stub := newGFStub (t )
387-
388- _ , err := execCommand (tc .args ... )
389- if err == nil {
390- t .Fatal ("expected required-flag error, got nil" )
391- }
392- if ! strings .Contains (err .Error (), "required" ) {
393- t .Errorf ("expected error to mention 'required', got %q" , err .Error ())
394- }
395- if stub .requests != 0 {
396- t .Errorf ("rows should not have been called: %d request(s)" , stub .requests )
397- }
398- })
399- }
400- }
401-
402303// --- normalizeRawTimeArgs --------------------------------------------------
403304
404305func TestNormalizeRawTimeArgsAcceptedFormats (t * testing.T ) {
@@ -469,17 +370,17 @@ func TestNormalizeRawTimeArgsInvalidValue(t *testing.T) {
469370 }
470371}
471372
472- // TestMonitQueryRowsRawModeNormalizesRFC3339 is the regression test for the
373+ // TestMonitQueryDataRawModeNormalizesRFC3339 is the regression test for the
473374// raw-vs-stats time format inconsistency: a raw-mode VictoriaLogs query given
474375// RFC3339 --args timestamps must reach the server as the unix-seconds form
475376// the raw query path requires.
476- func TestMonitQueryRowsRawModeNormalizesRFC3339 (t * testing.T ) {
377+ func TestMonitQueryDataRawModeNormalizesRFC3339 (t * testing.T ) {
477378 saveAndResetGlobals (t )
478379 stub := newGFStub (t )
479- stub .data = [ ]any {}
380+ stub .data = map [ string ]any {"format" : "query_result.v1" , "result" : map [ string ] any { "kind" : "records" , "records" : [] any {}} }
480381
481382 _ , err := execCommand (
482- "monit-query" , "rows " ,
383+ "monit-query" , "data " ,
483384 "--ds-type" , "victorialogs" ,
484385 "--ds-name" , "vl-prod" ,
485386 "--expr" , `{app="api"} |= "error"` ,
@@ -534,25 +435,3 @@ func TestMonitQueryDataInvalidArgs(t *testing.T) {
534435 t .Errorf ("data should not have been called: %d request(s)" , stub .requests )
535436 }
536437}
537-
538- func TestMonitQueryRowsInvalidArgs (t * testing.T ) {
539- saveAndResetGlobals (t )
540- stub := newGFStub (t )
541-
542- _ , err := execCommand (
543- "monit-query" , "rows" ,
544- "--ds-type" , "prometheus" ,
545- "--ds-name" , "prom-prod" ,
546- "--expr" , "up" ,
547- "--args" , "no-equals-sign" ,
548- )
549- if err == nil {
550- t .Fatal ("expected error for malformed --args, got nil" )
551- }
552- if ! strings .Contains (err .Error (), "--args" ) {
553- t .Errorf ("expected error to mention --args, got %q" , err .Error ())
554- }
555- if stub .requests != 0 {
556- t .Errorf ("rows should not have been called: %d request(s)" , stub .requests )
557- }
558- }
0 commit comments