Check for nil in embedded HostCatalog (#89)

pull/91/head
Michael Gaffney 6 years ago committed by GitHub
parent ef6edbd515
commit 4f3f9ed222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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{

Loading…
Cancel
Save