Skip to content

Commit a43e563

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 f70bf92 commit a43e563

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
@@ -3786,25 +3786,24 @@ func (s *MethodTestSuite) TestTailnetFunctions() {
37863786
}
37873787

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

38103809
func (s *MethodTestSuite) TestCryptoKeys() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy