@@ -571,6 +571,68 @@ func TestInvalidDataType(t *testing.T) {
571
571
require .NotNil (t , queryResult .Err ())
572
572
assert .Equal (t , "deviceId has unknown data type int" , queryResult .Err ().Error ())
573
573
}
574
+
575
+ func TestMissingDatatypeAnnotation (t * testing.T ) {
576
+ csvTable1 := `
577
+ #group,false,false,true,true,false,true,true,false,false,false
578
+ #default,_result,,,,,,,,,
579
+ ,result,table,_start,_stop,_time,deviceId,sensor,elapsed,note,start
580
+ ,,0,2020-04-28T12:36:50.990018157Z,2020-04-28T12:51:50.990018157Z,2020-04-28T12:38:11.480545389Z,1467463,BME280,1m1s,ZGF0YWluYmFzZTY0,2020-04-27T00:00:00Z
581
+ ,,0,2020-04-28T12:36:50.990018157Z,2020-04-28T12:51:50.990018157Z,2020-04-28T12:39:36.330153686Z,1467463,BME280,1h20m30.13245s,eHh4eHhjY2NjY2NkZGRkZA==,2020-04-28T00:00:00Z
582
+ `
583
+
584
+ reader := strings .NewReader (csvTable1 )
585
+ csvReader := csv .NewReader (reader )
586
+ csvReader .FieldsPerRecord = - 1
587
+ queryResult := & QueryTableResult {Closer : ioutil .NopCloser (reader ), csvReader : csvReader }
588
+ require .False (t , queryResult .Next ())
589
+ require .NotNil (t , queryResult .Err ())
590
+ assert .Equal (t , "parsing error, datatype annotation not found" , queryResult .Err ().Error ())
591
+ }
592
+
593
+ func TestDifferentNumberOfColumns (t * testing.T ) {
594
+ csvTable := `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,int,string,duration,base64Binary,dateTime:RFC3339
595
+ #group,false,false,true,true,false,true,true,false,false,
596
+ #default,_result,,,,,,,
597
+ ,result,table,_start,_stop,_time,deviceId,sensor,elapsed,note,start
598
+ ,,0,2020-04-28T12:36:50.990018157Z,2020-04-28T12:51:50.990018157Z,2020-04-28T12:38:11.480545389Z,1467463,BME280,1m1s,ZGF0YWluYmFzZTY0,2020-04-27T00:00:00Z,2345234
599
+ `
600
+
601
+ reader := strings .NewReader (csvTable )
602
+ csvReader := csv .NewReader (reader )
603
+ csvReader .FieldsPerRecord = - 1
604
+ queryResult := & QueryTableResult {Closer : ioutil .NopCloser (reader ), csvReader : csvReader }
605
+ require .False (t , queryResult .Next ())
606
+ require .NotNil (t , queryResult .Err ())
607
+ assert .Equal (t , "parsing error, row has different number of columns than table: 11 vs 10" , queryResult .Err ().Error ())
608
+ }
609
+
610
+ func TestFluxError (t * testing.T ) {
611
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
612
+ time .Sleep (100 * time .Millisecond )
613
+ if r .Method == http .MethodPost {
614
+ _ , _ = ioutil .ReadAll (r .Body )
615
+ w .Header ().Set ("Content-Type" , "application/json" )
616
+ w .WriteHeader (http .StatusBadRequest )
617
+ _ , _ = w .Write ([]byte (`{"code":"invalid","message":"compilation failed: loc 4:17-4:86: expected an operator between two expressions"}` ))
618
+ }
619
+ }))
620
+ defer server .Close ()
621
+ client := NewClient (server .URL , "a" )
622
+ queryApi := client .QueryApi ("org" )
623
+
624
+ result , err := queryApi .QueryRaw (context .Background (), "errored flux" , nil )
625
+ assert .Equal (t , "" , result )
626
+ require .NotNil (t , err )
627
+ assert .Equal (t , "invalid: compilation failed: loc 4:17-4:86: expected an operator between two expressions" , err .Error ())
628
+
629
+ tableRes , err := queryApi .Query (context .Background (), "errored flux" )
630
+ assert .Nil (t , tableRes )
631
+ require .NotNil (t , err )
632
+ assert .Equal (t , "invalid: compilation failed: loc 4:17-4:86: expected an operator between two expressions" , err .Error ())
633
+
634
+ }
635
+
574
636
func makeCSVstring (rows []string ) string {
575
637
csvTable := strings .Join (rows , "\r \n " )
576
638
return fmt .Sprintf ("%s\r \n " , csvTable )
0 commit comments