Skip to content

Commit 1a159c2

Browse files
author
Jordan Caussat
committed
Update project shared_with_groups: improve acceptance tests
1 parent 0a261de commit 1a159c2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

gitlab/resource_gitlab_project_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
8484
GroupID int
8585
GroupName string
8686
GroupAccessLevel int
87-
}{{0, "", 30}},
87+
}{{0, fmt.Sprintf("foo-name-%d", rInt), 30}},
8888
}),
8989
),
9090
},
@@ -106,7 +106,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
106106
GroupID int
107107
GroupName string
108108
GroupAccessLevel int
109-
}{{0, "", 30}, {0, "", 10}},
109+
}{{0, fmt.Sprintf("foo-name-%d", rInt), 10}, {0, fmt.Sprintf("foo2-name-%d", rInt), 30}},
110110
}),
111111
),
112112
},
@@ -251,11 +251,18 @@ func testAccCheckGitlabProjectAttributes(project *gitlab.Project, want *testAccG
251251
return fmt.Errorf("got visibility %q; want %q", project.Visibility, want.Visibility)
252252
}
253253

254-
for i, group := range project.SharedWithGroups {
255-
if group.GroupAccessLevel != want.SharedWithGroups[i].GroupAccessLevel {
256-
return fmt.Errorf("got shared with groups access: %d; want %d", group.GroupAccessLevel, want.SharedWithGroups[i].GroupAccessLevel)
254+
groupsToCheck := want.SharedWithGroups
255+
for _, group := range project.SharedWithGroups {
256+
for i, groupToCheck := range groupsToCheck {
257+
if group.GroupName == groupToCheck.GroupName && group.GroupAccessLevel == groupToCheck.GroupAccessLevel {
258+
groupsToCheck = append(groupsToCheck[:i], groupsToCheck[i+1:]...)
259+
break
260+
}
257261
}
258262
}
263+
if len(groupsToCheck) != 0 {
264+
return fmt.Errorf("got shared with groups: %v; want %v", project.SharedWithGroups, want.SharedWithGroups)
265+
}
259266

260267
return nil
261268
}

0 commit comments

Comments
 (0)