-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathaws_test.go
More file actions
68 lines (56 loc) · 1.7 KB
/
aws_test.go
File metadata and controls
68 lines (56 loc) · 1.7 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
67
68
package postgres
import (
"database/sql"
"fmt"
"regexp"
"testing"
sqlmock "github.com/DATA-DOG/go-sqlmock"
)
func TestApplyPgRepackPrivileges(t *testing.T) {
originalGetConnection := awsGetConnection
defer func() {
awsGetConnection = originalGetConnection
}()
mainDB, mainMock, err := sqlmock.New()
if err != nil {
t.Fatalf("failed to create main sqlmock: %v", err)
}
defer mainDB.Close()
tmpDB, tmpMock, err := sqlmock.New()
if err != nil {
t.Fatalf("failed to create tmp sqlmock: %v", err)
}
defer tmpDB.Close()
dbname := "test-db-dev"
owner := "test-db-dev-owner"
mainMock.ExpectQuery(regexp.QuoteMeta(fmt.Sprintf(GET_DB_OWNER, dbname))).
WillReturnRows(sqlmock.NewRows([]string{"pg_get_userbyid"}).AddRow(owner))
awsGetConnection = func(user, password, host, database, uriArgs string) (*sql.DB, error) {
if database != dbname {
t.Fatalf("expected database %s, got %s", dbname, database)
}
return tmpDB, nil
}
tmpMock.ExpectExec(regexp.QuoteMeta(fmt.Sprintf(AWS_ALTER_REPACK_DEFAULT_PRIVS_TABLES, owner))).
WillReturnResult(sqlmock.NewResult(0, 0))
tmpMock.ExpectExec(regexp.QuoteMeta(fmt.Sprintf(AWS_ALTER_REPACK_DEFAULT_PRIVS_SEQUENCES, owner))).
WillReturnResult(sqlmock.NewResult(0, 0))
c := &awspg{
pg: pg{
db: mainDB,
host: "localhost:5432",
user: "postgres",
pass: "postgres",
args: "sslmode=disable",
},
}
if err := c.applyPgRepackPrivileges(dbname); err != nil {
t.Fatalf("expected nil error, got %v", err)
}
if err := mainMock.ExpectationsWereMet(); err != nil {
t.Fatalf("main DB expectations were not met: %v", err)
}
if err := tmpMock.ExpectationsWereMet(); err != nil {
t.Fatalf("tmp DB expectations were not met: %v", err)
}
}