@@ -27,20 +27,48 @@ func TestQueryStableMultipleCases(t *testing.T) {
2727 expectError : false ,
2828 expectOutput : "\" abc\" \n " ,
2929 },
30+ {
31+ name : "Error Query" ,
32+ argv : []string {"clickhouse" , "--multiquery" , "--output-format=CSV" , "--query=XXX;" },
33+ expectError : true ,
34+ expectOutput : "" ,
35+ },
3036 }
3137
3238 // Iterate over the test cases
3339 for _ , tc := range testCases {
3440 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 )
3642
3743 // 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+ }
4472 }
4573 })
4674 }
0 commit comments