Skip to content

Commit

Permalink
Add UT for sorting roles required by blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
q2w committed Nov 26, 2024
1 parent 191a3b9 commit 1a50586
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
111 changes: 111 additions & 0 deletions cli/bpmetadata/tfconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,117 @@ func TestTFRoles(t *testing.T) {
}
}

func TestSortBlueprintRoles(t *testing.T) {
tests := []struct {
name string
in []*BlueprintRoles
want []*BlueprintRoles
}{
{
name: "simple list of roles",
in: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
},
},
},
want: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
},
},
},
},
{
name: "simple list of roles in reverse order",
in: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
},
want: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
},
},
},
},
{
name: "simple list of roles with differing len of slices",
in: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
"roles/owner",
},
},
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
},
want: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/cloudsql.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/storage.admin",
"roles/owner",
},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sortBlueprintRoles(tt.in)
assert.Equal(t, tt.in, tt.want)
})
}
}

func TestTFProviderVersions(t *testing.T) {
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/bpmetadata/tf/iam-multi-level.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ locals {
"roles/owner",
"roles/storage.admin"
]
}
}

0 comments on commit 1a50586

Please sign in to comment.