Fix canonical tags not getting assigned in the api resource. (#2144)
This commit is contained in:
4 files changed
+78
-15
No files matched your search
@@ -145,11 +145,33 @@ func TestLookupWorker(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
w := servers.TestWorker(t, conn, wrapper)
|
||||
w := servers.TestWorker(t, conn, wrapper,
|
||||
servers.WithName("name"),
|
||||
servers.WithDescription("description"),
|
||||
servers.WithAddress("address"),
|
||||
servers.WithWorkerTags(&servers.Tag{"key", "val"}))
|
||||
w, err = repo.UpsertWorkerStatus(context.Background(),
|
||||
servers.NewWorkerForStatus(w.GetScopeId(),
|
||||
servers.WithName(w.GetWorkerReportedName()),
|
||||
servers.WithAddress(w.GetWorkerReportedAddress()),
|
||||
servers.WithWorkerTags(&servers.Tag{
|
||||
Key: "config",
|
||||
Value: "test",
|
||||
})),
|
||||
servers.WithUpdateTags(true),
|
||||
servers.WithPublicId(w.GetPublicId()))
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
got, err := repo.LookupWorker(ctx, w.GetPublicId())
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, cmp.Diff(w.Worker, got.Worker, protocmp.Transform()))
|
||||
assert.Empty(t, cmp.Diff(w, got, protocmp.Transform()))
|
||||
assert.Equal(t, map[string][]string{"key": {"val"}}, got.GetApiTags())
|
||||
assert.Equal(t, map[string][]string{"config": {"test"}}, got.GetConfigTags())
|
||||
assert.Equal(t, map[string][]string{
|
||||
"key": {"val"},
|
||||
"config": {"test"},
|
||||
}, got.CanonicalTags())
|
||||
})
|
||||
t.Run("not found", func(t *testing.T) {
|
||||
got, err := repo.LookupWorker(ctx, "w_unknownid")
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers/store"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -103,6 +104,18 @@ func TestWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...Opti
|
||||
require.NotNil(t, wrk)
|
||||
opts := getOpts(opt...)
|
||||
|
||||
if len(opts.withWorkerTags) > 0 {
|
||||
var tags []interface{}
|
||||
for _, t := range opts.withWorkerTags {
|
||||
tags = append(tags, &store.WorkerTag{
|
||||
WorkerId: wrk.GetPublicId(),
|
||||
Key: t.Key,
|
||||
Value: t.Value,
|
||||
Source: "api",
|
||||
})
|
||||
}
|
||||
require.NoError(t, rw.CreateItems(ctx, tags))
|
||||
}
|
||||
var mask []string
|
||||
if opts.withName != "" {
|
||||
wrk.Name = opts.withName
|
||||
|
||||
Reference in new issue
Block a user