-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwrapper_test.go
68 lines (58 loc) · 1.78 KB
/
wrapper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package chdb
import (
"fmt"
"testing"
)
func TestQueryToBuffer(t *testing.T) {
// Create a temporary directory
// Define test cases
testCases := []struct {
name string
queryStr string
outputFormat string
udfPath string
expectedErrMsg string
expectedResult string
}{
{
name: "Basic Query",
queryStr: "SELECT 123",
outputFormat: "CSV",
udfPath: "",
expectedErrMsg: "",
expectedResult: "123\n",
},
{
name: "Error Query",
queryStr: "SELECT * FROM nonexist; ",
outputFormat: "CSV",
udfPath: "",
expectedErrMsg: "Code: 60. DB::Exception: Unknown table expression identifier 'nonexist' in scope SELECT * FROM nonexist. (UNKNOWN_TABLE)",
expectedResult: "",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Call queryToBuffer
result, err := Query(tc.queryStr, tc.outputFormat)
fmt.Println("result: ", result)
// Verify
if tc.expectedErrMsg != "" {
if err == nil {
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect error message: %v, got no error",
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedErrMsg)
} else {
if err.Error() != tc.expectedErrMsg {
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect error message: %v, got error message: %v",
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedErrMsg, err.Error())
}
}
} else {
if string(result.Buf()) != tc.expectedResult {
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect result: %v, got result: %v",
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedResult, string(result.Buf()))
}
}
})
}
}