forked from marcboeker/go-duckdb
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathconnection_test.go
More file actions
66 lines (60 loc) · 1.66 KB
/
connection_test.go
File metadata and controls
66 lines (60 loc) · 1.66 KB
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
package duckdb
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetTableNames(t *testing.T) {
db := openDbWrapper(t, ``)
defer closeDbWrapper(t, db)
conn := openConnWrapper(t, db, context.Background())
defer closeConnWrapper(t, conn)
tests := []struct {
name string
query string
qualified bool
expectedTables []string
expectedError string
}{
{
name: "valid query with multiple tables, qualified",
query: `SELECT * FROM schema1.table1, catalog3."schema.2"."table.2"`,
qualified: true,
expectedTables: []string{"schema1.table1", `catalog3."schema.2"."table.2"`},
},
{
name: "valid query with multiple tables, unqualified",
query: `SELECT * FROM schema1.table1, catalog3."schema.2"."table.2"`,
qualified: false,
expectedTables: []string{"table1", "table.2"},
},
{
name: "valid query with no tables",
query: "SELECT 1 as num",
expectedTables: nil,
},
{
name: "invalid query syntax",
query: "SELECT * FROM WHERE",
expectedError: "Parser Error: syntax error at or near \"WHERE\"",
},
{
name: "empty query",
query: "",
expectedError: "empty query",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tableNames, err := GetTableNames(conn, tt.query, tt.qualified)
if tt.expectedError != "" {
require.Contains(t, err.Error(), tt.expectedError)
assert.Nil(t, tableNames)
} else {
require.NoError(t, err)
assert.ElementsMatch(t, tt.expectedTables, tableNames)
}
})
}
}