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_teams_test.go
More file actions
104 lines (91 loc) · 3.72 KB
/
data_source_github_organization_role_teams_test.go
File metadata and controls
104 lines (91 loc) · 3.72 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
100
101
102
103
104
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceGithubOrganizationRoleTeams(t *testing.T) {
t.Run("get the organization role teams without error", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID)
roleId := 8134
config := fmt.Sprintf(`
resource "github_team" "test" {
name = "%s"
}
resource "github_organization_role_team" "test" {
role_id = %d
team_slug = github_team.test.slug
}
data "github_organization_role_teams" "test" {
role_id = %[2]d
depends_on = [
github_organization_role_team.test
]
}
`, teamName, 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_teams.test", "teams.#"),
resource.TestCheckResourceAttr("data.github_organization_role_teams.test", "teams.#", "1"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.team_id", "github_team.test", "id"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.slug", "github_team.test", "slug"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.name", "github_team.test", "name"),
),
},
},
})
})
t.Run("get indirect organization role teams without error", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName1 := fmt.Sprintf("%steam-1-%s", testResourcePrefix, randomID)
teamName2 := fmt.Sprintf("%steam-2-%s", testResourcePrefix, randomID)
roleId := 8134
config := fmt.Sprintf(`
resource "github_team" "test_1" {
name = "%s"
privacy = "closed"
}
resource "github_team" "test_2" {
name = "%s"
privacy = "closed"
parent_team_id = github_team.test_1.id
}
resource "github_organization_role_team" "test" {
role_id = %d
team_slug = github_team.test_1.slug
}
data "github_organization_role_teams" "test" {
role_id = %[3]d
depends_on = [
github_organization_role_team.test
]
}
`, teamName1, teamName2, 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_teams.test", "teams.#"),
resource.TestCheckResourceAttr("data.github_organization_role_teams.test", "teams.#", "2"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.team_id", "github_team.test_1", "id"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.slug", "github_team.test_1", "slug"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.0.name", "github_team.test_1", "name"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.1.team_id", "github_team.test_2", "id"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.1.slug", "github_team.test_2", "slug"),
resource.TestCheckResourceAttrPair("data.github_organization_role_teams.test", "teams.1.name", "github_team.test_2", "name"),
),
},
},
})
})
}