Skip to content

Commit

Permalink
only check for version and update_time
Browse files Browse the repository at this point in the history
  • Loading branch information
bosorawis committed Dec 27, 2024
1 parent 2643f04 commit c964ede
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions internal/daemon/controller/handlers/groups/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"slices"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/password"
Expand All @@ -25,7 +23,6 @@ import (
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/groups"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
Expand Down Expand Up @@ -658,7 +655,7 @@ func TestWriteActions(t *testing.T) {
testcases := []struct {
name string
roles []roleRequest
setup func(*testing.T) (*pbs.UpdateGroupRequest, *pb.Group)
setup func(t *testing.T) (*iam.Group, *pbs.UpdateGroupRequest)
wantErr error
}{
{
Expand All @@ -670,27 +667,21 @@ func TestWriteActions(t *testing.T) {
grantScopes: []string{globals.GrantScopeThis},
},
},
setup: func(t *testing.T) (*pbs.UpdateGroupRequest, *pb.Group) {
g := iam.TestGroup(t, conn, globals.GlobalPrefix, iam.WithName("name"), iam.WithDescription("description"))
noAuthCtx := auth.DisabledAuthTestContext(repoFn, globals.GlobalPrefix)
gotGroup, err := s.GetGroup(noAuthCtx, &pbs.GetGroupRequest{Id: g.PublicId})
setup: func(t *testing.T) (*iam.Group, *pbs.UpdateGroupRequest) {
g := iam.TestGroup(t, conn, globals.GlobalPrefix, iam.WithName(uuid.NewString()), iam.WithDescription(uuid.NewString()))
require.NoError(t, err)
input := &pbs.UpdateGroupRequest{
Id: g.PublicId,
Item: &pb.Group{
Name: &wrapperspb.StringValue{Value: "new-name"},
Description: &wrapperspb.StringValue{Value: "new-description"},
Name: &wrapperspb.StringValue{Value: uuid.NewString()},
Description: &wrapperspb.StringValue{Value: uuid.NewString()},
Version: 1,
},
UpdateMask: &fieldmaskpb.FieldMask{
Paths: []string{"name", "description"},
},
}
want := gotGroup.Item
want.Name = input.Item.Name
want.Description = input.Item.Description
want.Version = 2
return input, want
return g, input
},
wantErr: nil,
},
Expand All @@ -703,7 +694,7 @@ func TestWriteActions(t *testing.T) {
grantScopes: []string{globals.GrantScopeChildren},
},
},
setup: func(t *testing.T) (*pbs.UpdateGroupRequest, *pb.Group) {
setup: func(t *testing.T) (*iam.Group, *pbs.UpdateGroupRequest) {
g := iam.TestGroup(t, conn, globals.GlobalPrefix, iam.WithName("name"), iam.WithDescription("description"))
input := &pbs.UpdateGroupRequest{
Id: g.PublicId,
Expand All @@ -716,7 +707,7 @@ func TestWriteActions(t *testing.T) {
Paths: []string{"name", "description"},
},
}
return input, nil
return g, input
},
wantErr: handlers.ForbiddenError(),
},
Expand All @@ -725,27 +716,16 @@ func TestWriteActions(t *testing.T) {
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
fullGrantAuthCtx := genAuthTokenCtx(t, ctx, conn, wrap, iamRepo, tc.roles)
input, want := tc.setup(t)
originalGroup, input := tc.setup(t)
got, err := s.UpdateGroup(fullGrantAuthCtx, input)
if tc.wantErr != nil {
require.Error(t, err)
require.ErrorIs(t, err, tc.wantErr)
return
}
require.NoError(t, err)

// remove update time from assertion due to its unpredictability
got.Item.UpdatedTime = nil
want.UpdatedTime = nil

require.Empty(t, cmp.Diff(
got.Item,
want,
protocmp.Transform(),
cmpopts.SortSlices(func(a, b string) bool {
return a < b
}),
))
require.Equal(t, uint32(2), got.Item.Version)
require.True(t, got.Item.UpdatedTime.AsTime().After(originalGroup.UpdateTime.AsTime()))
})
}
})
Expand Down

0 comments on commit c964ede

Please sign in to comment.