Skip to content

Commit d3911a5

Browse files
committed
test(dbauthz): migrate TestDBCrypt to mocked db
- Convert DBCrypt subtests to s.Mocked with gomock expectations - Remove reliance on real DB for setup - Keeps consistent style with prior groups
1 parent b7ff778 commit d3911a5

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,25 +3783,24 @@ func (s *MethodTestSuite) TestTailnetFunctions() {
37833783
}
37843784

37853785
func (s *MethodTestSuite) TestDBCrypt() {
3786-
s.Run("GetDBCryptKeys", s.Subtest(func(db database.Store, check *expects) {
3787-
check.Args().
3788-
Asserts(rbac.ResourceSystem, policy.ActionRead).
3789-
Returns([]database.DBCryptKey{})
3790-
}))
3791-
s.Run("InsertDBCryptKey", s.Subtest(func(db database.Store, check *expects) {
3792-
check.Args(database.InsertDBCryptKeyParams{}).
3793-
Asserts(rbac.ResourceSystem, policy.ActionCreate).
3794-
Returns()
3795-
}))
3796-
s.Run("RevokeDBCryptKey", s.Subtest(func(db database.Store, check *expects) {
3797-
err := db.InsertDBCryptKey(context.Background(), database.InsertDBCryptKeyParams{
3798-
ActiveKeyDigest: "revoke me",
3799-
})
3800-
s.NoError(err)
3801-
check.Args("revoke me").
3802-
Asserts(rbac.ResourceSystem, policy.ActionUpdate).
3803-
Returns()
3804-
}))
3786+
s.Run("GetDBCryptKeys", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3787+
dbm.EXPECT().GetDBCryptKeys(gomock.Any()).Return([]database.DBCryptKey{}, nil).AnyTimes()
3788+
check.Args().
3789+
Asserts(rbac.ResourceSystem, policy.ActionRead).
3790+
Returns([]database.DBCryptKey{})
3791+
}))
3792+
s.Run("InsertDBCryptKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3793+
dbm.EXPECT().InsertDBCryptKey(gomock.Any(), database.InsertDBCryptKeyParams{}).Return(nil).AnyTimes()
3794+
check.Args(database.InsertDBCryptKeyParams{}).
3795+
Asserts(rbac.ResourceSystem, policy.ActionCreate).
3796+
Returns()
3797+
}))
3798+
s.Run("RevokeDBCryptKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3799+
dbm.EXPECT().RevokeDBCryptKey(gomock.Any(), "revoke me").Return(nil).AnyTimes()
3800+
check.Args("revoke me").
3801+
Asserts(rbac.ResourceSystem, policy.ActionUpdate).
3802+
Returns()
3803+
}))
38053804
}
38063805

38073806
func (s *MethodTestSuite) TestCryptoKeys() {

0 commit comments

Comments
 (0)