From 596d1ad86a186b345cc64e662822a4b792bb0c3a Mon Sep 17 00:00:00 2001 From: irenarindos Date: Fri, 3 Jan 2025 12:11:17 -0500 Subject: [PATCH] refact(server): prefix test method with Test --- .../handlers/workers/worker_service_test.go | 4 ++-- internal/server/repository_worker_test.go | 16 ++++++++-------- internal/server/testing.go | 6 +++--- internal/session/job_session_cleanup_test.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/daemon/controller/handlers/workers/worker_service_test.go b/internal/daemon/controller/handlers/workers/worker_service_test.go index 7a9d9b9bb7..c3a7f394a9 100644 --- a/internal/daemon/controller/handlers/workers/worker_service_test.go +++ b/internal/daemon/controller/handlers/workers/worker_service_test.go @@ -148,7 +148,7 @@ func TestGet(t *testing.T) { server.WithDescription("test pki worker description"), server.WithTestPkiWorkerAuthorizedKeyId(&pkiWorkerKeyId)) // Add config tags to the created worker - pkiWorker, err = server.UpsertAndReturnWorker(context.Background(), t, + pkiWorker, err = server.TestUpsertAndReturnWorker(context.Background(), t, server.NewWorker(pkiWorker.GetScopeId(), server.WithAddress("test pki worker address"), server.WithLocalStorageState(server.AvailableLocalStorageState.String()), @@ -203,7 +203,7 @@ func TestGet(t *testing.T) { ) // Add config tags to the created worker - managedPkiWorker, err = server.UpsertAndReturnWorker(context.Background(), t, + managedPkiWorker, err = server.TestUpsertAndReturnWorker(context.Background(), t, server.NewWorker(managedPkiWorker.GetScopeId(), server.WithAddress("test managed pki worker address"), server.WithLocalStorageState(server.AvailableLocalStorageState.String()), diff --git a/internal/server/repository_worker_test.go b/internal/server/repository_worker_test.go index 553aae2469..be571e38b5 100644 --- a/internal/server/repository_worker_test.go +++ b/internal/server/repository_worker_test.go @@ -238,7 +238,7 @@ func TestUpsertWorkerStatus(t *testing.T) { server.WithAddress("address"), server.WithName("config_name1"), server.WithDescription("kms_description1"), ) - worker, err := server.UpsertAndReturnWorker(ctx, t, wStatus1, repo) + worker, err := server.TestUpsertAndReturnWorker(ctx, t, wStatus1, repo) require.NoError(t, err) assert.True(t, strings.HasPrefix(worker.GetPublicId(), "w_")) @@ -253,7 +253,7 @@ func TestUpsertWorkerStatus(t *testing.T) { // update again and see updated last status time wStatus2 := server.NewWorker(scope.Global.String(), server.WithAddress("new_address"), server.WithName("config_name1"), server.WithReleaseVersion("test-version")) - worker, err = server.UpsertAndReturnWorker(ctx, t, wStatus2, repo) + worker, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus2, repo) require.NoError(t, err) assert.Greater(t, worker.GetLastStatusTime().AsTime(), worker.GetCreateTime().AsTime()) assert.Equal(t, "config_name1", worker.Name) @@ -272,7 +272,7 @@ func TestUpsertWorkerStatus(t *testing.T) { wStatus3 := server.NewWorker(scope.Global.String(), server.WithAddress("new_address"), server.WithName("config_name1"), server.WithOperationalState("shutdown"), server.WithReleaseVersion("Boundary v0.11.0")) - worker, err = server.UpsertAndReturnWorker(ctx, t, wStatus3, repo) + worker, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus3, repo) require.NoError(t, err) assert.Greater(t, worker.GetLastStatusTime().AsTime(), worker.GetCreateTime().AsTime()) // Version does not change for status updates @@ -285,7 +285,7 @@ func TestUpsertWorkerStatus(t *testing.T) { server.WithAddress("new_address"), server.WithName("config_name1"), server.WithOperationalState("shutdown"), server.WithReleaseVersion("Boundary v0.11.0"), server.WithLocalStorageState("available")) - worker, err = server.UpsertAndReturnWorker(ctx, t, wStatus4, repo) + worker, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus4, repo) require.NoError(t, err) assert.Greater(t, worker.GetLastStatusTime().AsTime(), worker.GetCreateTime().AsTime()) // Version does not change for status updates @@ -306,7 +306,7 @@ func TestUpsertWorkerStatus(t *testing.T) { wStatus1 := server.NewWorker(scope.Global.String(), server.WithAddress("pki_address"), server.WithDescription("pki_description2"), server.WithReleaseVersion("test-version")) - worker, err := server.UpsertAndReturnWorker(ctx, t, wStatus1, repo, server.WithKeyId(pkiWorkerKeyId), server.WithReleaseVersion("test-version")) + worker, err := server.TestUpsertAndReturnWorker(ctx, t, wStatus1, repo, server.WithKeyId(pkiWorkerKeyId), server.WithReleaseVersion("test-version")) require.NoError(t, err) assert.True(t, strings.HasPrefix(worker.GetPublicId(), "w_")) @@ -625,7 +625,7 @@ func TestTagUpdatingListing(t *testing.T) { Value: "value2", })) - worker1, err = server.UpsertAndReturnWorker(ctx, t, wStatus, repo, server.WithUpdateTags(true)) + worker1, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus, repo, server.WithUpdateTags(true)) require.NoError(err) assert.Len(t, worker1.CanonicalTags(), 1) assert.ElementsMatch(t, []string{"value1", "value2"}, worker1.CanonicalTags()["tag1"]) @@ -643,13 +643,13 @@ func TestTagUpdatingListing(t *testing.T) { Key: "tag22", Value: "value22", })) - worker1, err = server.UpsertAndReturnWorker(ctx, t, wStatus, repo) + worker1, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus, repo) require.NoError(err) assert.Len(t, worker1.CanonicalTags(), 1) assert.ElementsMatch(t, []string{"value1", "value2"}, worker1.CanonicalTags()["tag1"]) // Update tags and test again - worker1, err = server.UpsertAndReturnWorker(ctx, t, wStatus, repo, server.WithUpdateTags(true)) + worker1, err = server.TestUpsertAndReturnWorker(ctx, t, wStatus, repo, server.WithUpdateTags(true)) require.NoError(err) assert.Len(t, worker1.CanonicalTags(), 1) assert.ElementsMatch(t, []string{"value21", "value22"}, worker1.CanonicalTags()["tag22"]) diff --git a/internal/server/testing.go b/internal/server/testing.go index a0024476f5..7f33f321e9 100644 --- a/internal/server/testing.go +++ b/internal/server/testing.go @@ -125,7 +125,7 @@ func TestKmsWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...O } wrk := NewWorker(scope.Global.String(), opt...) - wrk, err = UpsertAndReturnWorker(ctx, t, wrk, serversRepo) + wrk, err = TestUpsertAndReturnWorker(ctx, t, wrk, serversRepo) require.NoError(t, err) require.NoError(t, err) require.NotNil(t, wrk) @@ -224,8 +224,8 @@ func TestLookupWorkerByName(ctx context.Context, t *testing.T, name string, serv return nil, nil } -// UpsertAndReturnWorker upserts and returns a worker -func UpsertAndReturnWorker(ctx context.Context, t *testing.T, w *Worker, serversRepo *Repository, opt ...Option) (*Worker, error) { +// TestUpsertAndReturnWorker upserts and returns a worker +func TestUpsertAndReturnWorker(ctx context.Context, t *testing.T, w *Worker, serversRepo *Repository, opt ...Option) (*Worker, error) { workerId, err := serversRepo.UpsertWorkerStatus(ctx, w, opt...) require.NoError(t, err) require.NotEmpty(t, workerId) diff --git a/internal/session/job_session_cleanup_test.go b/internal/session/job_session_cleanup_test.go index 156878b33f..8de4cd828b 100644 --- a/internal/session/job_session_cleanup_test.go +++ b/internal/session/job_session_cleanup_test.go @@ -278,7 +278,7 @@ func TestCloseConnectionsForDeadWorkers(t *testing.T) { t.Helper() pubId := w.GetPublicId() w.PublicId = "" - wkr, err := server.UpsertAndReturnWorker(ctx, t, w, serversRepo, server.WithPublicId(pubId)) + wkr, err := server.TestUpsertAndReturnWorker(ctx, t, w, serversRepo, server.WithPublicId(pubId)) require.NoError(err) return wkr }