Skip to content

Commit

Permalink
refact(server): prefix test method with Test
Browse files Browse the repository at this point in the history
  • Loading branch information
irenarindos authored and hugoghx committed Jan 7, 2025
1 parent 4424b73 commit 596d1ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down
16 changes: 8 additions & 8 deletions internal/server/repository_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_"))
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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_"))
Expand Down Expand Up @@ -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"])
Expand All @@ -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"])
Expand Down
6 changes: 3 additions & 3 deletions internal/server/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/session/job_session_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 596d1ad

Please sign in to comment.