|
1 | 1 | package chdbstable |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "testing" |
| 4 | + "testing" |
5 | 5 | ) |
6 | 6 |
|
7 | 7 | // TestCase defines the structure of a test case |
8 | 8 | type TestCase struct { |
9 | | - name string // Name of the test case |
10 | | - argv []string // Arguments to pass to QueryStable |
11 | | - expectError bool // Whether an error is expected |
12 | | - expectOutput string // Expected output |
| 9 | + name string // Name of the test case |
| 10 | + argv []string // Arguments to pass to QueryStable |
| 11 | + expectError bool // Whether an error is expected |
| 12 | + expectOutput string // Expected output |
13 | 13 | } |
14 | 14 |
|
15 | 15 | func TestQueryStableMultipleCases(t *testing.T) { |
16 | | - // Define a series of test cases |
17 | | - testCases := []TestCase{ |
18 | | - { |
19 | | - name: "Single Query", |
20 | | - argv: []string{"clickhouse", "--multiquery", "--output-format=CSV", "--query=SELECT 123;"}, |
21 | | - expectError: false, |
22 | | - expectOutput: "123\n", |
23 | | - }, |
24 | | - { |
25 | | - name: "Multiple Queries", |
26 | | - argv: []string{"clickhouse", "--multiquery", "--output-format=CSV", "--query=SELECT 'abc';"}, |
27 | | - expectError: false, |
28 | | - expectOutput: "abc", |
29 | | - }, |
30 | | - } |
| 16 | + // Define a series of test cases |
| 17 | + testCases := []TestCase{ |
| 18 | + { |
| 19 | + name: "Single Query", |
| 20 | + argv: []string{"clickhouse", "--multiquery", "--output-format=CSV", "--query=SELECT 123;"}, |
| 21 | + expectError: false, |
| 22 | + expectOutput: "123\n", |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "Multiple Queries", |
| 26 | + argv: []string{"clickhouse", "--multiquery", "--output-format=CSV", "--query=SELECT 'abc';"}, |
| 27 | + expectError: false, |
| 28 | + expectOutput: "abc", |
| 29 | + }, |
| 30 | + } |
31 | 31 |
|
32 | | - // Iterate over the test cases |
33 | | - for _, tc := range testCases { |
34 | | - t.Run(tc.name, func(t *testing.T) { |
35 | | - result := QueryStable(len(tc.argv), tc.argv) |
| 32 | + // Iterate over the test cases |
| 33 | + for _, tc := range testCases { |
| 34 | + t.Run(tc.name, func(t *testing.T) { |
| 35 | + result := QueryStable(len(tc.argv), tc.argv) |
36 | 36 |
|
37 | | - // 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 | | - } |
| 37 | + // 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 | 41 |
|
42 | | - if (result != nil) && (string(result) != tc.expectOutput) { |
43 | | - t.Errorf("QueryStable() with args %v, expect output: %v, got output: %v", tc.argv, tc.expectOutput, string(result.Buf())) |
44 | | - } |
45 | | - }) |
46 | | - } |
| 42 | + if (result != nil) && (string(result) != tc.expectOutput) { |
| 43 | + t.Errorf("QueryStable() with args %v, expect output: %v, got output: %v", tc.argv, tc.expectOutput, string(result.Buf())) |
| 44 | + } |
| 45 | + }) |
| 46 | + } |
47 | 47 | } |
0 commit comments