@@ -27,20 +27,48 @@ func TestQueryStableMultipleCases(t *testing.T) {
27
27
expectError : false ,
28
28
expectOutput : "\" abc\" \n " ,
29
29
},
30
+ {
31
+ name : "Error Query" ,
32
+ argv : []string {"clickhouse" , "--multiquery" , "--output-format=CSV" , "--query=XXX;" },
33
+ expectError : true ,
34
+ expectOutput : "" ,
35
+ },
30
36
}
31
37
32
38
// Iterate over the test cases
33
39
for _ , tc := range testCases {
34
40
t .Run (tc .name , func (t * testing.T ) {
35
- result := QueryStable (len (tc .argv ), tc .argv )
41
+ result , err := QueryStable (len (tc .argv ), tc .argv )
36
42
37
43
// Assert based on the expected outcome of the test case
38
- if (result == nil ) && tc .expectError {
39
- t .Errorf ("QueryStable() with args %v, expect error: %v, got result: %v" , tc .argv , tc .expectError , result )
40
- }
41
-
42
- if (result != nil ) && string (result .Buf ()) != tc .expectOutput {
43
- t .Errorf ("QueryStable() with args %v, expect output: %v, got output: %v" , tc .argv , tc .expectOutput , string (result .Buf ()))
44
+ if tc .expectError {
45
+ if err == nil {
46
+ t .Errorf ("Expected error, but got nil" )
47
+ }
48
+ } else {
49
+ if err != nil {
50
+ t .Errorf ("Expected no error, but got %v" , err )
51
+ } else {
52
+ if result == nil {
53
+ t .Errorf ("Expected non-nil result, but got nil" )
54
+ } else {
55
+ if result .cResult == nil {
56
+ t .Errorf ("Expected non-nil cResult, but got nil" )
57
+ } else {
58
+ if result .cResult .error_message != nil {
59
+ t .Errorf ("Expected nil error_message, but got %v" , result .cResult .error_message )
60
+ } else {
61
+ if result .cResult .buf == nil {
62
+ t .Errorf ("Expected non-nil output, but got nil" )
63
+ } else {
64
+ if tc .expectOutput != string (result .String ()) {
65
+ t .Errorf ("Expected output %v, but got %v" , tc .expectOutput , string (result .String ()))
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
44
72
}
45
73
})
46
74
}
0 commit comments