Skip to content

Commit 61a5916

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 3454dc8 commit 61a5916

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
@@ -3714,25 +3714,24 @@ func (s *MethodTestSuite) TestTailnetFunctions() {
37143714
}
37153715

37163716
func (s *MethodTestSuite) TestDBCrypt() {
3717-
s.Run("GetDBCryptKeys", s.Subtest(func(db database.Store, check *expects) {
3718-
check.Args().
3719-
Asserts(rbac.ResourceSystem, policy.ActionRead).
3720-
Returns([]database.DBCryptKey{})
3721-
}))
3722-
s.Run("InsertDBCryptKey", s.Subtest(func(db database.Store, check *expects) {
3723-
check.Args(database.InsertDBCryptKeyParams{}).
3724-
Asserts(rbac.ResourceSystem, policy.ActionCreate).
3725-
Returns()
3726-
}))
3727-
s.Run("RevokeDBCryptKey", s.Subtest(func(db database.Store, check *expects) {
3728-
err := db.InsertDBCryptKey(context.Background(), database.InsertDBCryptKeyParams{
3729-
ActiveKeyDigest: "revoke me",
3730-
})
3731-
s.NoError(err)
3732-
check.Args("revoke me").
3733-
Asserts(rbac.ResourceSystem, policy.ActionUpdate).
3734-
Returns()
3735-
}))
3717+
s.Run("GetDBCryptKeys", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3718+
dbm.EXPECT().GetDBCryptKeys(gomock.Any()).Return([]database.DBCryptKey{}, nil).AnyTimes()
3719+
check.Args().
3720+
Asserts(rbac.ResourceSystem, policy.ActionRead).
3721+
Returns([]database.DBCryptKey{})
3722+
}))
3723+
s.Run("InsertDBCryptKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3724+
dbm.EXPECT().InsertDBCryptKey(gomock.Any(), database.InsertDBCryptKeyParams{}).Return(nil).AnyTimes()
3725+
check.Args(database.InsertDBCryptKeyParams{}).
3726+
Asserts(rbac.ResourceSystem, policy.ActionCreate).
3727+
Returns()
3728+
}))
3729+
s.Run("RevokeDBCryptKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
3730+
dbm.EXPECT().RevokeDBCryptKey(gomock.Any(), "revoke me").Return(nil).AnyTimes()
3731+
check.Args("revoke me").
3732+
Asserts(rbac.ResourceSystem, policy.ActionUpdate).
3733+
Returns()
3734+
}))
37363735
}
37373736

37383737
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