Check for nil in embedded HostCatalog (#89)
This commit is contained in:
1 parent
ef6edbd515
commit
4f3f9ed222
2 files changed
+27
-1
No files matched your search
@@ -53,6 +53,9 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O
|
||||
if c == nil {
|
||||
return nil, fmt.Errorf("create: static host catalog: %w", db.ErrNilParameter)
|
||||
}
|
||||
if c.HostCatalog == nil {
|
||||
return nil, fmt.Errorf("create: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter)
|
||||
}
|
||||
if c.HostCatalog.ScopeId == "" {
|
||||
return nil, fmt.Errorf("create: static host catalog: no scope id: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
@@ -109,6 +112,9 @@ func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, fieldMas
|
||||
if c == nil {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: %w", db.ErrNilParameter)
|
||||
}
|
||||
if c.HostCatalog == nil {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter)
|
||||
}
|
||||
if c.PublicId == "" {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: missing public id: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
@@ -138,6 +138,11 @@ func TestRepository_CreateCatalog(t *testing.T) {
|
||||
name: "nil-catalog",
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-catalog",
|
||||
in: &HostCatalog{},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
},
|
||||
{
|
||||
name: "valid-no-options",
|
||||
in: &HostCatalog{
|
||||
@@ -183,7 +188,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
assert.NotNil(repo)
|
||||
_, prj := iam.TestScopes(t, conn)
|
||||
if tt.in != nil {
|
||||
if tt.in != nil && tt.in.HostCatalog != nil {
|
||||
tt.in.ScopeId = prj.GetPublicId()
|
||||
assert.Empty(tt.in.PublicId)
|
||||
}
|
||||
@@ -310,6 +315,12 @@ func TestRepository_UpdateCatalog(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
makeEmbeddedNil := func() func(*HostCatalog) *HostCatalog {
|
||||
return func(c *HostCatalog) *HostCatalog {
|
||||
return &HostCatalog{}
|
||||
}
|
||||
}
|
||||
|
||||
deletePublicId := func() func(*HostCatalog) *HostCatalog {
|
||||
return func(c *HostCatalog) *HostCatalog {
|
||||
c.PublicId = ""
|
||||
@@ -351,6 +362,15 @@ func TestRepository_UpdateCatalog(t *testing.T) {
|
||||
masks: []string{"Name", "Description"},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-catalog",
|
||||
orig: &HostCatalog{
|
||||
HostCatalog: &store.HostCatalog{},
|
||||
},
|
||||
chgFn: makeEmbeddedNil(),
|
||||
masks: []string{"Name", "Description"},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
},
|
||||
{
|
||||
name: "no-public-id",
|
||||
orig: &HostCatalog{
|
||||
|
||||
Reference in new issue
Block a user