refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)

* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
This commit is contained in:
Jim authored and GitHub committed 2022-01-05 14:38:38 -05:00
1 parent 002d004114
commit 591ec476e7
160 files changed
+4369 -3164

No files matched your search

+9 -9
View File
@@ -105,7 +105,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com"))
new := AllocAudClaim()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", am.PublicId, "alice.com"))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{am.PublicId, "alice.com"}))
tests := []struct {
name string
@@ -147,7 +147,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", orig.OidcMethodId, orig.Aud))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{orig.OidcMethodId, orig.Aud}))
require.NoError(err)
@@ -158,7 +158,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", after.OidcMethodId, after.Aud))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{after.OidcMethodId, after.Aud}))
assert.True(proto.Equal(orig, after))
})
@@ -186,7 +186,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithCertificates(x509))
new := AllocCertificate()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", am.PublicId, pem))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{am.PublicId, pem}))
tests := []struct {
name string
@@ -228,7 +228,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", orig.OidcMethodId, orig.Cert))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{orig.OidcMethodId, orig.Cert}))
require.NoError(err)
@@ -239,7 +239,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", after.OidcMethodId, after.Cert))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{after.OidcMethodId, after.Cert}))
assert.True(proto.Equal(orig, after))
})
@@ -263,7 +263,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithSigningAlgs(RS256))
new := AllocSigningAlg()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", am.PublicId, RS256))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{am.PublicId, RS256}))
tests := []struct {
name string
@@ -305,7 +305,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", orig.OidcMethodId, orig.Alg))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{orig.OidcMethodId, orig.Alg}))
require.NoError(err)
@@ -316,7 +316,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", after.OidcMethodId, after.Alg))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{after.OidcMethodId, after.Alg}))
assert.True(proto.Equal(orig, after))
})