From 902ff31126731fa74f36bd6b8daa2eb0f76aa796 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 8 Jul 2020 17:41:28 -0500 Subject: [PATCH] Fix up some tests after merging --- internal/db/migrations/postgres.gen.go | 2 +- internal/db/migrations/postgres/06_iam.up.sql | 2 +- internal/db/read_writer.go | 4 ++-- internal/iam/role_test.go | 17 +++++------------ 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/internal/db/migrations/postgres.gen.go b/internal/db/migrations/postgres.gen.go index 9272c1669d..5825754071 100644 --- a/internal/db/migrations/postgres.gen.go +++ b/internal/db/migrations/postgres.gen.go @@ -775,7 +775,7 @@ create table iam_role ( name text, description text, scope_id wt_scope_id not null references iam_scope(public_id) on delete cascade on update cascade, - grant_scope_id wt_public_id not null references iam_scope(public_id) on delete cascade on update cascade, + grant_scope_id wt_scope_id not null references iam_scope(public_id) on delete cascade on update cascade, unique(name, scope_id), disabled boolean not null default false, -- version allows optimistic locking of the role when modifying the role diff --git a/internal/db/migrations/postgres/06_iam.up.sql b/internal/db/migrations/postgres/06_iam.up.sql index 748674ad26..b56bcc014f 100644 --- a/internal/db/migrations/postgres/06_iam.up.sql +++ b/internal/db/migrations/postgres/06_iam.up.sql @@ -317,7 +317,7 @@ create table iam_role ( name text, description text, scope_id wt_scope_id not null references iam_scope(public_id) on delete cascade on update cascade, - grant_scope_id wt_public_id not null references iam_scope(public_id) on delete cascade on update cascade, + grant_scope_id wt_scope_id not null references iam_scope(public_id) on delete cascade on update cascade, unique(name, scope_id), disabled boolean not null default false, -- version allows optimistic locking of the role when modifying the role diff --git a/internal/db/read_writer.go b/internal/db/read_writer.go index 1caa4a8417..b0ffc6fdca 100644 --- a/internal/db/read_writer.go +++ b/internal/db/read_writer.go @@ -244,7 +244,7 @@ func (rw *Db) Create(ctx context.Context, i interface{}, opt ...Option) error { if !opts.withSkipVetForWrite { if vetter, ok := i.(VetForWriter); ok { if err := vetter.VetForWrite(ctx, rw, CreateOp); err != nil { - return fmt.Errorf("create: vet for write failed %w", err) + return fmt.Errorf("create: vet for write failed: %w", err) } } } @@ -412,7 +412,7 @@ func (rw *Db) Update(ctx context.Context, i interface{}, fieldMaskPaths []string if !opts.withSkipVetForWrite { if vetter, ok := i.(VetForWriter); ok { if err := vetter.VetForWrite(ctx, rw, UpdateOp, WithFieldMaskPaths(fieldMaskPaths), WithNullPaths(setToNullPaths)); err != nil { - return NoRowsAffected, fmt.Errorf("update: vet for write failed %w", err) + return NoRowsAffected, fmt.Errorf("update: vet for write failed: %w", err) } } } diff --git a/internal/iam/role_test.go b/internal/iam/role_test.go index 52dc21b386..5e9f3a9175 100644 --- a/internal/iam/role_test.go +++ b/internal/iam/role_test.go @@ -340,7 +340,7 @@ func Test_RoleUpdate(t *testing.T) { grantScopeId: proj2.PublicId, }, wantErr: true, - wantErrMsg: "update: failed pq: invalid to set grant_scope_id to non-same scope_id when role scope type is project", + wantErrMsg: "update: failed: pq: invalid to set grant_scope_id to non-same scope_id when role scope type is project", }, { name: "set grant scope in org", @@ -361,7 +361,7 @@ func Test_RoleUpdate(t *testing.T) { grantScopeId: proj2.PublicId, }, wantErr: true, - wantErrMsg: "update: failed pq: grant_scope_id is not a child project of the role scope", + wantErrMsg: "update: failed: pq: grant_scope_id is not a child project of the role scope", }, { name: "set grant scope in global", @@ -371,6 +371,8 @@ func Test_RoleUpdate(t *testing.T) { scopeId: org.PublicId, grantScopeId: "global", }, + wantErr: true, + wantErrMsg: "update: failed: pq: grant_scope_id is not a child project of the role scope", }, { name: "set grant scope to parent", @@ -381,16 +383,7 @@ func Test_RoleUpdate(t *testing.T) { grantScopeId: org2.PublicId, }, wantErr: true, - wantErrMsg: "update: failed pq: grant_scope_id is not a child project of the role scope", - }, - { - name: "set grant scope from global", - args: args{ - name: "set grant scope from global", - fieldMaskPaths: []string{"GrantScopeId"}, - scopeId: "global", - grantScopeId: org.PublicId, - }, + wantErrMsg: "update: failed: pq: invalid to set grant_scope_id to non-same scope_id when role scope type is project", }, } for _, tt := range tests {