Some testing fixes (#2193)

This commit is contained in:
Todd authored and GitHub committed 2022-06-15 10:47:25 -07:00
1 parent beecbbb8a2
commit 90a999d3fe
5 files changed
+158 -60

No files matched your search

+10 -8
View File
@@ -58,8 +58,9 @@ func TestRootCertificate(ctx context.Context, t *testing.T, conn *db.DB, kmsKey
return cert
}
func TestWorkerAuth(ctx context.Context, t *testing.T, conn *db.DB, worker *Worker, kmsKey string) *WorkerAuth {
func TestWorkerAuth(t *testing.T, conn *db.DB, worker *Worker, kmsKey string) *WorkerAuth {
t.Helper()
ctx := context.Background()
rw := db.New(conn)
wSignPubKey := populateBytes(defaultLength)
wEncPubKey := populateBytes(defaultLength)
@@ -104,12 +105,10 @@ func TestKmsWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
if opts.withAddress != "" {
address = opts.withAddress
}
id, err := newWorkerIdFromScopeAndName(ctx, scope.Global.String(), name)
require.NoError(t, err)
wrk := NewWorker(scope.Global.String(),
WithName(name),
WithAddress(address))
wrk, err = serversRepo.UpsertWorkerStatus(ctx, wrk, WithPublicId(id))
wrk, err = serversRepo.UpsertWorkerStatus(ctx, wrk)
require.NoError(t, err)
require.NotNil(t, wrk)
@@ -120,7 +119,7 @@ func TestKmsWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
WorkerId: wrk.GetPublicId(),
Key: t.Key,
Value: t.Value,
Source: "api",
Source: "configuration",
})
}
require.NoError(t, rw.CreateItems(ctx, tags))
@@ -137,11 +136,12 @@ func TestKmsWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
require.Equal(t, 1, n)
require.NotNil(t, wrk)
}
wrk, err = serversRepo.LookupWorker(ctx, wrk.GetPublicId())
require.NoError(t, err)
return wrk
}
// TestKmsWorker inserts a worker into the db to satisfy foreign key constraints.
// TestPkiWorker inserts a worker into the db to satisfy foreign key constraints.
// The worker provided fields are auto generated. WithName and WithDescription,
// are applied to the resource name, description and address if
// present.
@@ -168,10 +168,12 @@ func TestPkiWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
WorkerId: wrk.GetPublicId(),
Key: t.Key,
Value: t.Value,
Source: "config",
Source: "configuration",
})
}
require.NoError(t, rw.CreateItems(ctx, tags))
}
wrk, err = serversRepo.LookupWorker(ctx, wrk.GetPublicId())
require.NoError(t, err)
return wrk
}