Skip to content

Commit bf7f06a

Browse files
committed
feat: add unit tests
1 parent 76a99d7 commit bf7f06a

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616

1717
require (
1818
cel.dev/expr v0.24.0 // indirect
19+
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
1920
github.com/Masterminds/semver/v3 v3.4.0 // indirect
2021
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
2122
github.com/beorn7/perks v1.0.1 // indirect

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
22
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
3+
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
4+
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
35
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
46
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
57
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
@@ -82,6 +84,7 @@ github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE
8284
github.com/joshdk/go-junit v1.0.0/go.mod h1:TiiV0PqkaNfFXjEiyjWM3XXrhVyCa1K4Zfga6W52ung=
8385
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
8486
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
87+
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
8588
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
8689
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
8790
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=

pkg/postgres/aws.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const (
1616
AWS_ALTER_REPACK_DEFAULT_PRIVS_SEQUENCES = `ALTER DEFAULT PRIVILEGES FOR ROLE "%s" IN SCHEMA "repack" GRANT USAGE, SELECT ON SEQUENCES TO PUBLIC`
1717
)
1818

19+
var awsGetConnection = GetConnection
20+
1921
func newAWSPG(postgres *pg) PG {
2022
return &awspg{
2123
*postgres,
@@ -56,15 +58,19 @@ func (c *awspg) CreateExtension(dbname, extension string) error {
5658
return nil
5759
}
5860

61+
return c.applyPgRepackPrivileges(dbname)
62+
}
63+
64+
func (c *awspg) applyPgRepackPrivileges(dbname string) error {
5965
var owner string
6066
// Resolve current database owner role to target ALTER DEFAULT PRIVILEGES FOR ROLE.
61-
err = c.db.QueryRow(fmt.Sprintf(GET_DB_OWNER, dbname)).Scan(&owner)
67+
err := c.db.QueryRow(fmt.Sprintf(GET_DB_OWNER, dbname)).Scan(&owner)
6268
if err != nil {
6369
return err
6470
}
6571

6672
// Execute pg_repack privilege statements in the target database.
67-
tmpDb, err := GetConnection(c.user, c.pass, c.host, dbname, c.args)
73+
tmpDb, err := awsGetConnection(c.user, c.pass, c.host, dbname, c.args)
6874
if err != nil {
6975
return err
7076
}

0 commit comments

Comments
 (0)