-
Notifications
You must be signed in to change notification settings - Fork 951
Expand file tree
/
Copy pathdata_source_github_organization_test.go
More file actions
178 lines (163 loc) · 8.74 KB
/
data_source_github_organization_test.go
File metadata and controls
178 lines (163 loc) · 8.74 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)
func TestAccGithubOrganizationDataSource(t *testing.T) {
t.Run("uses provider owner when name is not set", func(t *testing.T) {
config := `data "github_organization" "test" {}`
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("login"), knownvalue.StringExact(testAccConf.owner)),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("orgname"), knownvalue.StringExact(testAccConf.owner)),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("node_id"), knownvalue.NotNull()),
statecheck.ExpectKnownValue("data.github_organization.test", tfjsonpath.New("plan"), knownvalue.NotNull()),
},
},
},
})
})
t.Run("queries for an organization without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_organization" "test" {
name = "%s"
}
`, testAccConf.owner)
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.github_organization.test", "login", testAccConf.owner),
resource.TestCheckResourceAttr("data.github_organization.test", "orgname", testAccConf.owner),
resource.TestCheckResourceAttrSet("data.github_organization.test", "node_id"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "plan"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "repositories.#"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members.#"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "two_factor_requirement_enabled"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "default_repository_permission"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_allowed_repository_creation_type"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_public_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_private_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_internal_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_fork_private_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "web_commit_signoff_required"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_pages"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_public_pages"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_create_private_pages"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "advanced_security_enabled_for_new_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "dependabot_alerts_enabled_for_new_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "dependabot_security_updates_enabled_for_new_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "dependency_graph_enabled_for_new_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "secret_scanning_enabled_for_new_repositories"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "secret_scanning_push_protection_enabled_for_new_repositories"),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
})
t.Run("queries for an organization with archived repos", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repoName := fmt.Sprintf("%srepo-archived-%s", testResourcePrefix, randomID)
config := `
resource "github_repository" "archived" {
name = "%s"
archived = %t
}
data "github_organization" "skip_archived" {
name = "%[3]s"
ignore_archived_repos = true
depends_on = [
github_repository.archived,
]
}
data "github_organization" "all_repos" {
name = "%[3]s"
ignore_archived_repos = false
depends_on = [
github_repository.archived,
]
}
output "should_be_false" {
value = contains(data.github_organization.skip_archived.repositories, github_repository.archived.full_name)
}
output "should_be_true" {
value = contains(data.github_organization.all_repos.repositories, github_repository.archived.full_name)
}
`
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(config, repoName, false, testAccConf.owner), // We are removing the option to create archived repositories
},
{
Config: fmt.Sprintf(config, repoName, true, testAccConf.owner),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckOutput("should_be_false", "false"),
resource.TestCheckOutput("should_be_true", "true"),
),
},
},
})
})
t.Run("queries for an organization summary_only without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_organization" "test" {
name = "%s"
summary_only = true
}
`, testAccConf.owner)
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.github_organization.test", "login", testAccConf.owner),
resource.TestCheckResourceAttr("data.github_organization.test", "orgname", testAccConf.owner),
resource.TestCheckResourceAttrSet("data.github_organization.test", "node_id"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "plan"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "repositories.#"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members.#"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "two_factor_requirement_enabled"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "default_repository_permission"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_allowed_repository_creation_type"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_public_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_private_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_internal_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_fork_private_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "web_commit_signoff_required"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_pages"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_public_pages"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "members_can_create_private_pages"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "advanced_security_enabled_for_new_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "dependabot_alerts_enabled_for_new_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "dependabot_security_updates_enabled_for_new_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "dependency_graph_enabled_for_new_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "secret_scanning_enabled_for_new_repositories"),
resource.TestCheckNoResourceAttr("data.github_organization.test", "secret_scanning_push_protection_enabled_for_new_repositories"),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
})
}