Skip to content

Commit 74c5685

Browse files
authored
Creating custom skip function for group_ldap_link tests. (#328)
* Creating custom skip function for group_ldap_link tests. Co-authored-by: Jason Carlsen <[email protected]>
1 parent c7cf214 commit 74c5685

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

gitlab/resource_gitlab_group_ldap_link_test.go

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,54 @@ func TestAccGitlabGroupLdapLink_basic(t *testing.T) {
2525
t.Fatalf("[ERROR] Failed to load test data: %s", err.Error())
2626
}
2727

28-
if testLdapLink.CN == "default" || testLdapLink.Provider == "default" {
29-
t.Skipf("[WARNING] Skipping test until test data is configured in %s.", testDataFile)
30-
} else {
31-
resource.Test(t, resource.TestCase{
32-
Providers: testAccProviders,
33-
CheckDestroy: testAccCheckGitlabGroupLdapLinkDestroy,
34-
Steps: []resource.TestStep{
35-
36-
// Create a group LDAP link as a developer (uses testAccGitlabGroupLdapLinkCreateConfig for Config)
37-
{
38-
SkipFunc: isRunningInCE,
39-
Config: testAccGitlabGroupLdapLinkCreateConfig(rInt, &testLdapLink),
40-
Check: resource.ComposeTestCheckFunc(
41-
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.foo", &ldapLink),
42-
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
43-
accessLevel: fmt.Sprintf("developer"),
44-
})),
45-
},
46-
47-
// Update the group LDAP link to change the access level (uses testAccGitlabGroupLdapLinkUpdateConfig for Config)
48-
{
49-
SkipFunc: isRunningInCE,
50-
Config: testAccGitlabGroupLdapLinkUpdateConfig(rInt, &testLdapLink),
51-
Check: resource.ComposeTestCheckFunc(
52-
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.foo", &ldapLink),
53-
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
54-
accessLevel: fmt.Sprintf("maintainer"),
55-
})),
56-
},
57-
58-
// Force create the same group LDAP link in a different resource (uses testAccGitlabGroupLdapLinkForceCreateConfig for Config)
59-
{
60-
SkipFunc: isRunningInCE,
61-
Config: testAccGitlabGroupLdapLinkForceCreateConfig(rInt, &testLdapLink),
62-
Check: resource.ComposeTestCheckFunc(
63-
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.bar", &ldapLink),
64-
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
65-
accessLevel: fmt.Sprintf("developer"),
66-
})),
67-
},
28+
resource.Test(t, resource.TestCase{
29+
Providers: testAccProviders,
30+
CheckDestroy: testAccCheckGitlabGroupLdapLinkDestroy,
31+
Steps: []resource.TestStep{
32+
33+
// Create a group LDAP link as a developer (uses testAccGitlabGroupLdapLinkCreateConfig for Config)
34+
{
35+
SkipFunc: testAccGitlabGroupLdapLinkSkipFunc(testLdapLink.CN, testLdapLink.Provider),
36+
Config: testAccGitlabGroupLdapLinkCreateConfig(rInt, &testLdapLink),
37+
Check: resource.ComposeTestCheckFunc(
38+
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.foo", &ldapLink),
39+
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
40+
accessLevel: fmt.Sprintf("developer"),
41+
})),
42+
},
43+
44+
// Update the group LDAP link to change the access level (uses testAccGitlabGroupLdapLinkUpdateConfig for Config)
45+
{
46+
SkipFunc: testAccGitlabGroupLdapLinkSkipFunc(testLdapLink.CN, testLdapLink.Provider),
47+
Config: testAccGitlabGroupLdapLinkUpdateConfig(rInt, &testLdapLink),
48+
Check: resource.ComposeTestCheckFunc(
49+
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.foo", &ldapLink),
50+
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
51+
accessLevel: fmt.Sprintf("maintainer"),
52+
})),
53+
},
54+
55+
// Force create the same group LDAP link in a different resource (uses testAccGitlabGroupLdapLinkForceCreateConfig for Config)
56+
{
57+
SkipFunc: testAccGitlabGroupLdapLinkSkipFunc(testLdapLink.CN, testLdapLink.Provider),
58+
Config: testAccGitlabGroupLdapLinkForceCreateConfig(rInt, &testLdapLink),
59+
Check: resource.ComposeTestCheckFunc(
60+
testAccCheckGitlabGroupLdapLinkExists("gitlab_group_ldap_link.bar", &ldapLink),
61+
testAccCheckGitlabGroupLdapLinkAttributes(&ldapLink, &testAccGitlabGroupLdapLinkExpectedAttributes{
62+
accessLevel: fmt.Sprintf("developer"),
63+
})),
6864
},
69-
})
65+
},
66+
})
67+
}
68+
69+
func testAccGitlabGroupLdapLinkSkipFunc(testCN string, testProvider string) func() (bool, error) {
70+
return func() (bool, error) {
71+
if testCN == "default" || testProvider == "default" {
72+
return true, nil
73+
}
74+
75+
return isRunningInCE()
7076
}
7177
}
7278

0 commit comments

Comments
 (0)