|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package target
|
|
|
|
|
package target_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
@ -9,6 +9,8 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/globals"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/alias/target"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/alias/target/store"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
dbassert "github.com/hashicorp/boundary/internal/db/assert"
|
|
|
|
|
@ -34,9 +36,9 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
in *Alias
|
|
|
|
|
opts []Option
|
|
|
|
|
want *Alias
|
|
|
|
|
in *target.Alias
|
|
|
|
|
opts []target.Option
|
|
|
|
|
want *target.Alias
|
|
|
|
|
errContains string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
@ -45,26 +47,26 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "nil-embedded-alias",
|
|
|
|
|
in: &Alias{},
|
|
|
|
|
in: &target.Alias{},
|
|
|
|
|
errContains: "nil embedded Alias",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no-value",
|
|
|
|
|
in: &Alias{Alias: &store.Alias{
|
|
|
|
|
in: &target.Alias{Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
}},
|
|
|
|
|
errContains: "no value",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no-scope",
|
|
|
|
|
in: &Alias{Alias: &store.Alias{
|
|
|
|
|
in: &target.Alias{Alias: &store.Alias{
|
|
|
|
|
Value: "global",
|
|
|
|
|
}},
|
|
|
|
|
errContains: "no scope",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "specified-public-id",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
PublicId: "alt_1234567890",
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
@ -75,13 +77,13 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-with-value",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-value",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-value",
|
|
|
|
|
@ -90,14 +92,14 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-with-name",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-name",
|
|
|
|
|
Name: "test-name-repo",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-name",
|
|
|
|
|
@ -107,14 +109,14 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-with-description",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-description",
|
|
|
|
|
Description: ("test-description-repo"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid-with-description",
|
|
|
|
|
@ -124,14 +126,14 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-with-destination-id",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid.with.destination.id",
|
|
|
|
|
DestinationId: tar.GetPublicId(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "valid.with.destination.id",
|
|
|
|
|
@ -141,7 +143,7 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "unknown-destination-id",
|
|
|
|
|
in: &Alias{
|
|
|
|
|
in: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "unknown.destination.id",
|
|
|
|
|
@ -156,7 +158,7 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
tt := tt
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
assert.NoError(err)
|
|
|
|
|
assert.NotNil(repo)
|
|
|
|
|
got, err := repo.CreateAlias(ctx, tt.in, tt.opts...)
|
|
|
|
|
@ -179,10 +181,10 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
t.Run("invalid-duplicate-aliases-case-insensitive", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
assert.NoError(err)
|
|
|
|
|
assert.NotNil(repo)
|
|
|
|
|
in := &Alias{
|
|
|
|
|
in := &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "test-value-repo",
|
|
|
|
|
@ -207,10 +209,10 @@ func TestRepository_CreateAlias(t *testing.T) {
|
|
|
|
|
t.Run("invalid-duplicate-name", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
assert.NoError(err)
|
|
|
|
|
assert.NotNil(repo)
|
|
|
|
|
in := &Alias{
|
|
|
|
|
in := &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
ScopeId: "global",
|
|
|
|
|
Value: "test-value-name-1",
|
|
|
|
|
@ -254,73 +256,73 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
_, _ = tar1, tar2
|
|
|
|
|
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, repo)
|
|
|
|
|
|
|
|
|
|
changeValue := func(s string) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
changeValue := func(s string) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.Value = s
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeName := func(s string) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
changeName := func(s string) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.Name = s
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeDestinationId := func(s string) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
changeDestinationId := func(s string) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.DestinationId = s
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeHostId := func(s string) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
changeHostId := func(s string) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.HostId = s
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeDescription := func(s string) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
changeDescription := func(s string) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.Description = s
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makeNil := func() func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
makeNil := func() func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makeEmbeddedNil := func() func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
return &Alias{}
|
|
|
|
|
makeEmbeddedNil := func() func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
return &target.Alias{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deletePublicId := func() func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
deletePublicId := func() func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.PublicId = ""
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nonExistentPublicId := func() func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
nonExistentPublicId := func() func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
c.PublicId = "alt_OOOOOOOOOO"
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combine := func(fns ...func(c *Alias) *Alias) func(*Alias) *Alias {
|
|
|
|
|
return func(c *Alias) *Alias {
|
|
|
|
|
combine := func(fns ...func(c *target.Alias) *target.Alias) func(*target.Alias) *target.Alias {
|
|
|
|
|
return func(c *target.Alias) *target.Alias {
|
|
|
|
|
for _, fn := range fns {
|
|
|
|
|
c = fn(c)
|
|
|
|
|
}
|
|
|
|
|
@ -330,16 +332,16 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
orig *Alias
|
|
|
|
|
chgFn func(*Alias) *Alias
|
|
|
|
|
orig *target.Alias
|
|
|
|
|
chgFn func(*target.Alias) *target.Alias
|
|
|
|
|
masks []string
|
|
|
|
|
want *Alias
|
|
|
|
|
want *target.Alias
|
|
|
|
|
wantCount int
|
|
|
|
|
wantIsErr errors.Code
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "nil-alias",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "nil-alias",
|
|
|
|
|
},
|
|
|
|
|
@ -350,7 +352,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "nil-embedded-alias",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "nil-embedded-alias",
|
|
|
|
|
},
|
|
|
|
|
@ -361,7 +363,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no-public-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "no-public-id",
|
|
|
|
|
},
|
|
|
|
|
@ -372,7 +374,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "updating-non-existent-alias",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "updating-non-existent-alias",
|
|
|
|
|
},
|
|
|
|
|
@ -383,7 +385,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty-field-mask",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "empty-field-mask",
|
|
|
|
|
},
|
|
|
|
|
@ -393,7 +395,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "read-only-fields-in-field-mask",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "read-only-fields-in-field-mask",
|
|
|
|
|
},
|
|
|
|
|
@ -404,7 +406,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "unknown-field-in-field-mask",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "unknown-field-in-field-mask",
|
|
|
|
|
},
|
|
|
|
|
@ -415,14 +417,14 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-value",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-value",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeValue("change-value-updated"),
|
|
|
|
|
masks: []string{"Value"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-value-updated",
|
|
|
|
|
},
|
|
|
|
|
@ -431,7 +433,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-name",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-name",
|
|
|
|
|
Name: "change-name",
|
|
|
|
|
@ -439,7 +441,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeName("change-name-updated"),
|
|
|
|
|
masks: []string{"Name"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-name",
|
|
|
|
|
Name: "change-name-updated",
|
|
|
|
|
@ -449,7 +451,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "clear-name",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "clear-name",
|
|
|
|
|
Name: "clear-name",
|
|
|
|
|
@ -457,7 +459,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeName(""),
|
|
|
|
|
masks: []string{"Name"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "clear-name",
|
|
|
|
|
},
|
|
|
|
|
@ -466,7 +468,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-destination-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-destination-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -474,7 +476,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeDestinationId(tar2.GetPublicId()),
|
|
|
|
|
masks: []string{"DestinationId"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-destination-id",
|
|
|
|
|
DestinationId: tar2.GetPublicId(),
|
|
|
|
|
@ -484,7 +486,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-destination-id-to-unknown",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-destination-id-to-unknown",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -496,7 +498,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "delete-destination-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-destination-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -504,7 +506,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeDestinationId(tar2.GetPublicId()),
|
|
|
|
|
masks: []string{"DestinationId"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-destination-id",
|
|
|
|
|
},
|
|
|
|
|
@ -513,7 +515,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "delete-destination-also-deletes-host-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-destination-also-deletes-host-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -522,7 +524,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeDestinationId(""),
|
|
|
|
|
masks: []string{"DestinationId"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-destination-also-deletes-host-id",
|
|
|
|
|
},
|
|
|
|
|
@ -531,7 +533,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-host-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-host-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -540,7 +542,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeHostId("hst_0987654321"),
|
|
|
|
|
masks: []string{"HostId"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-host-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -551,7 +553,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "delete-host-id",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-host-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -560,7 +562,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeHostId(""),
|
|
|
|
|
masks: []string{"HostId"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-host-id",
|
|
|
|
|
DestinationId: tar1.GetPublicId(),
|
|
|
|
|
@ -570,7 +572,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-description",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-description",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -578,7 +580,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: changeDescription("test-update-description-repo"),
|
|
|
|
|
masks: []string{"Description"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-description",
|
|
|
|
|
Description: "test-update-description-repo",
|
|
|
|
|
@ -588,7 +590,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "change-value-and-description",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-value-and-description",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -596,7 +598,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
chgFn: combine(changeDescription("test-update-description-repo"), changeValue("change-value-and-description-updated")),
|
|
|
|
|
masks: []string{"Value", "Description"},
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "change-value-and-description-updated",
|
|
|
|
|
Description: "test-update-description-repo",
|
|
|
|
|
@ -606,7 +608,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "delete-value",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-value",
|
|
|
|
|
},
|
|
|
|
|
@ -617,7 +619,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "delete-description",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-description",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -625,7 +627,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
masks: []string{"Description"},
|
|
|
|
|
chgFn: combine(changeDescription(""), changeValue("delete-description-updated")),
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "delete-description",
|
|
|
|
|
},
|
|
|
|
|
@ -634,7 +636,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "do-not-delete-value",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "do-not-delete-value",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -642,7 +644,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
masks: []string{"Description"},
|
|
|
|
|
chgFn: combine(changeDescription("test-update-description-repo"), changeValue("")),
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "do-not-delete-value",
|
|
|
|
|
Description: "test-update-description-repo",
|
|
|
|
|
@ -652,7 +654,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "do-not-delete-description",
|
|
|
|
|
orig: &Alias{
|
|
|
|
|
orig: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "do-not-delete-description",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -660,7 +662,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
masks: []string{"Value"},
|
|
|
|
|
chgFn: combine(changeDescription(""), changeValue("do-not-delete-description-updated")),
|
|
|
|
|
want: &Alias{
|
|
|
|
|
want: &target.Alias{
|
|
|
|
|
Alias: &store.Alias{
|
|
|
|
|
Value: "do-not-delete-description-updated",
|
|
|
|
|
Description: "test-description-repo",
|
|
|
|
|
@ -713,7 +715,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("invalid-duplicate-values", func(t *testing.T) {
|
|
|
|
|
value := "test-dup-value"
|
|
|
|
|
c1 := TestAlias(t, db.New(conn), "test")
|
|
|
|
|
c1 := target.TestAlias(t, db.New(conn), "test")
|
|
|
|
|
c1.Value = value
|
|
|
|
|
got1, gotCount1, err := repo.UpdateAlias(context.Background(), c1, 1, []string{"value"})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
@ -721,7 +723,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
assert.Equal(t, value, got1.Value)
|
|
|
|
|
assert.Equal(t, 1, gotCount1, "row count")
|
|
|
|
|
|
|
|
|
|
c2 := TestAlias(t, db.New(conn), "test2")
|
|
|
|
|
c2 := target.TestAlias(t, db.New(conn), "test2")
|
|
|
|
|
c2.Value = value
|
|
|
|
|
got2, gotCount2, err := repo.UpdateAlias(context.Background(), c2, 1, []string{"value"})
|
|
|
|
|
assert.Truef(t, errors.Match(errors.T(errors.NotUnique), err), "want err code: %v got err: %v", errors.NotUnique, err)
|
|
|
|
|
@ -731,7 +733,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("invalid-duplicate-name", func(t *testing.T) {
|
|
|
|
|
name := "test-dup-name"
|
|
|
|
|
c1 := TestAlias(t, db.New(conn), "duplicate.name.test")
|
|
|
|
|
c1 := target.TestAlias(t, db.New(conn), "duplicate.name.test")
|
|
|
|
|
c1.Name = name
|
|
|
|
|
got1, gotCount1, err := repo.UpdateAlias(context.Background(), c1, 1, []string{"name"})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
@ -739,7 +741,7 @@ func TestRepository_UpdateAlias(t *testing.T) {
|
|
|
|
|
assert.Equal(t, name, got1.Name)
|
|
|
|
|
assert.Equal(t, 1, gotCount1, "row count")
|
|
|
|
|
|
|
|
|
|
c2 := TestAlias(t, db.New(conn), "duplicate.name.test2")
|
|
|
|
|
c2 := target.TestAlias(t, db.New(conn), "duplicate.name.test2")
|
|
|
|
|
c2.Name = name
|
|
|
|
|
got2, gotCount2, err := repo.UpdateAlias(context.Background(), c2, 1, []string{"name"})
|
|
|
|
|
assert.Truef(t, errors.Match(errors.T(errors.NotUnique), err), "want err code: %v got err: %v", errors.NotUnique, err)
|
|
|
|
|
@ -753,15 +755,15 @@ func TestRepository_LookupAlias(t *testing.T) {
|
|
|
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
|
|
|
rw := db.New(conn)
|
|
|
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
|
al := TestAlias(t, rw, "one")
|
|
|
|
|
badId, err := newAliasId(ctx)
|
|
|
|
|
al := target.TestAlias(t, rw, "one")
|
|
|
|
|
badId, err := db.NewPublicId(ctx, globals.TargetAliasPrefix)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, badId)
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
id string
|
|
|
|
|
want *Alias
|
|
|
|
|
want *target.Alias
|
|
|
|
|
wantErr errors.Code
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
@ -787,7 +789,7 @@ func TestRepository_LookupAlias(t *testing.T) {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kms)
|
|
|
|
|
assert.NoError(err)
|
|
|
|
|
assert.NotNil(repo)
|
|
|
|
|
|
|
|
|
|
@ -818,12 +820,12 @@ func TestRepository_DeleteAlias(t *testing.T) {
|
|
|
|
|
kmsCache := kms.TestKms(t, conn, wrapper)
|
|
|
|
|
require.NoError(t, kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader)))
|
|
|
|
|
|
|
|
|
|
repo, err := NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
repo, err := target.NewRepository(ctx, rw, rw, kmsCache)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
require.NotNil(t, repo)
|
|
|
|
|
|
|
|
|
|
al := TestAlias(t, rw, "deleted.alias")
|
|
|
|
|
badId, err := newAliasId(ctx)
|
|
|
|
|
al := target.TestAlias(t, rw, "deleted.alias")
|
|
|
|
|
badId, err := db.NewPublicId(ctx, globals.TargetAliasPrefix)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, badId)
|
|
|
|
|
|
|
|
|
|
|