forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_github_organization_role_users_test.go
More file actions
99 lines (85 loc) · 2.94 KB
/
data_source_github_organization_role_users_test.go
File metadata and controls
99 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
t.Run("get the organization role users without error", func(t *testing.T) {
if testAccConf.testOrgUser == "" {
t.Skip("Skipping test because no organization user has been configured")
}
roleId := 8134
config := fmt.Sprintf(`
resource "github_organization_role_user" "test" {
role_id = %d
login = "%s"
}
data "github_organization_role_users" "test" {
role_id = %[1]d
depends_on = [
github_organization_role_user.test
]
}
`, roleId, testAccConf.testOrgUser)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"),
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"),
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"),
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser),
),
},
},
})
})
t.Run("get indirect organization role users without error", func(t *testing.T) {
if testAccConf.testOrgUser == "" {
t.Skip("Skipping test because no organization user has been configured")
}
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID)
roleId := 8134
config := fmt.Sprintf(`
resource "github_team" "test" {
name = "%s"
privacy = "closed"
}
resource "github_team_membership" "test" {
team_id = github_team.test.id
username = "%s"
}
resource "github_organization_role_team" "test" {
role_id = %d
team_slug = github_team.test.slug
}
data "github_organization_role_users" "test" {
role_id = %[3]d
depends_on = [
github_organization_role_team.test
]
}
`, teamName, testAccConf.testOrgUser, roleId)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"),
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"),
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"),
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser),
),
},
},
})
})
}