Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cli/bpmetadata/tfconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,11 @@ func sortBlueprintRoles(r []*BlueprintRoles) {
return len(r[i].Roles) < len(r[j].Roles)
}

// 3. Sort by the first role (if available)
if len(r[i].Roles) > 0 && len(r[j].Roles) > 0 {
return r[i].Roles[0] < r[j].Roles[0]
// 3. Sort by each role in the list
for k := 0; k < len(r[i].Roles); k++ {
if r[i].Roles[k] != r[j].Roles[k] {
return r[i].Roles[k] < r[j].Roles[k]
}
}

return false
Comment thread
apeabody marked this conversation as resolved.
Expand Down
39 changes: 39 additions & 0 deletions cli/bpmetadata/tfconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,45 @@ func TestSortBlueprintRoles(t *testing.T) {
},
},
},
{
name: "sort by roles list content (real world)",
in: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/compute.admin",
"roles/container.admin",
"roles/storage.admin",
},
},
{
Level: "Project",
Roles: []string{
"roles/compute.admin",
"roles/container.admin",
"roles/iam.serviceAccountUser",
},
},
},
want: []*BlueprintRoles{
{
Level: "Project",
Roles: []string{
"roles/compute.admin",
"roles/container.admin",
"roles/iam.serviceAccountUser",
},
},
{
Level: "Project",
Roles: []string{
"roles/compute.admin",
"roles/container.admin",
"roles/storage.admin",
},
},
},
},
}

for _, tt := range tests {
Expand Down
Loading