Skip to content

Commit

Permalink
chore(kv): define failing test for URM on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMac committed Feb 12, 2020
1 parent 6b7ba49 commit 6209c5e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
38 changes: 37 additions & 1 deletion kv/urm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,27 @@ func initUserResourceMappingService(s kv.Store, f influxdbtesting.UserResourceFi
t.Fatalf("error initializing urm service: %v", err)
}

for _, o := range f.Organizations {
if err := svc.CreateOrganization(ctx, o); err != nil {
t.Fatalf("failed to create org %q", err)
}
}

for _, u := range f.Users {
if err := svc.CreateUser(ctx, u); err != nil {
t.Fatalf("failed to create user %q", err)
}
}

for _, b := range f.Buckets {
if err := svc.PutBucket(ctx, b); err != nil {
t.Fatalf("failed to create bucket %q", err)
}
}

for _, m := range f.UserResourceMappings {
if err := svc.CreateUserResourceMapping(ctx, m); err != nil {
t.Fatalf("failed to populate mappings")
t.Fatalf("failed to populate mappings %q", err)
}
}

Expand All @@ -61,6 +79,24 @@ func initUserResourceMappingService(s kv.Store, f influxdbtesting.UserResourceFi
t.Logf("failed to remove user resource mapping: %v", err)
}
}

for _, b := range f.Buckets {
if err := svc.DeleteBucket(ctx, b.ID); err != nil {
t.Logf("failed to delete org", err)
}
}

for _, u := range f.Users {
if err := svc.DeleteUser(ctx, u.ID); err != nil {
t.Fatalf("failed to delete user %q", err)
}
}

for _, o := range f.Organizations {
if err := svc.DeleteOrganization(ctx, o.ID); err != nil {
t.Logf("failed to delete org", err)
}
}
}
}

Expand Down
43 changes: 43 additions & 0 deletions testing/user_resource_mapping_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var mappingCmpOptions = cmp.Options{

// UserResourceFields includes prepopulated data for mapping tests
type UserResourceFields struct {
Organizations []*platform.Organization
Users []*platform.User
Buckets []*platform.Bucket
UserResourceMappings []*platform.UserResourceMapping
}

Expand Down Expand Up @@ -243,6 +246,46 @@ func DeleteUserResourceMapping(
err: fmt.Errorf("user to resource mapping not found"),
},
},
{
name: "delete user resource mapping for org",
fields: UserResourceFields{
Organizations: []*platform.Organization{
{
ID: MustIDBase16(orgOneID),
Name: "organization1",
},
},
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
},
Buckets: []*platform.Bucket{
{
ID: MustIDBase16(bucketOneID),
Name: "bucket1",
OrgID: MustIDBase16(orgOneID),
},
},
UserResourceMappings: []*platform.UserResourceMapping{
{
ResourceID: MustIDBase16(orgOneID),
ResourceType: platform.OrgsResourceType,
MappingType: platform.UserMappingType,
UserID: MustIDBase16(userOneID),
UserType: platform.Member,
},
},
},
args: args{
resourceID: MustIDBase16(orgOneID),
userID: MustIDBase16(userOneID),
},
wants: wants{
mappings: []*platform.UserResourceMapping{},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 6209c5e

Please sign in to comment.