-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnowflake_test.go
88 lines (83 loc) · 2.13 KB
/
snowflake_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package sql
import (
"context"
"database/sql"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/require"
)
func TestSnowflakeRepository_ListDatabases(t *testing.T) {
ctx, db, mock, r := initSnowflakeRepoTest(t)
defer func() { _ = db.Close() }()
dbRows := sqlmock.NewRows([]string{"name"}).AddRow("db1").AddRow("db2")
mock.ExpectQuery(snowflakeDatabaseQuery).WillReturnRows(dbRows)
dbs, err := r.ListDatabases(ctx)
require.NoError(t, err)
require.ElementsMatch(t, []string{"db1", "db2"}, dbs)
}
func TestNewSnowflakeConfigFromMap(t *testing.T) {
tests := []struct {
name string
cfg map[string]any
want SnowflakeConfig
wantErr require.ErrorAssertionFunc
}{
{
name: "Returns config when all keys are present",
cfg: map[string]any{
configAccount: "testAccount",
configRole: "testRole",
configWarehouse: "testWarehouse",
},
want: SnowflakeConfig{
Account: "testAccount",
Role: "testRole",
Warehouse: "testWarehouse",
},
},
{
name: "Returns error when account key is missing",
cfg: map[string]any{
configRole: "testRole",
configWarehouse: "testWarehouse",
},
wantErr: require.Error,
},
{
name: "Returns error when role key is missing",
cfg: map[string]any{
configAccount: "testAccount",
configWarehouse: "testWarehouse",
},
wantErr: require.Error,
},
{
name: "Returns error when warehouse key is missing",
cfg: map[string]any{
configAccount: "testAccount",
configRole: "testRole",
},
wantErr: require.Error,
},
}
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
got, err := NewSnowflakeConfigFromMap(tt.cfg)
if tt.wantErr == nil {
tt.wantErr = require.NoError
}
tt.wantErr(t, err)
require.Equal(t, tt.want, got)
},
)
}
}
func initSnowflakeRepoTest(t *testing.T) (context.Context, *sql.DB, sqlmock.Sqlmock, *SnowflakeRepository) {
ctx := context.Background()
db, mock, err := sqlmock.New()
require.NoError(t, err)
return ctx, db, mock, &SnowflakeRepository{
generic: NewGenericRepositoryFromDB(RepoTypeSnowflake, "dbName", db),
}
}