forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_github_organization_settings_test.go
183 lines (166 loc) · 5.16 KB
/
resource_github_organization_settings_test.go
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
179
180
181
182
183
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
func TestAccGithubOrganizationSettings(t *testing.T) {
t.Run("creates organization settings without error", func(t *testing.T) {
config := `
resource "github_organization_settings" "test" {
billing_email = "test@example.com"
company = "Test Company"
blog = "https://example.com"
email = "test@example.com"
twitter_username = "Test"
location = "Test Location"
name = "Test Name"
description = "Test Description"
has_organization_projects = true
has_repository_projects = true
default_repository_permission = "read"
members_can_create_repositories = true
members_can_create_public_repositories = true
members_can_create_private_repositories = true
members_can_create_internal_repositories = false
members_can_create_pages = true
members_can_create_public_pages = true
members_can_create_private_pages = true
members_can_fork_private_repositories = true
web_commit_signoff_required = true
advanced_security_enabled_for_new_repositories = false
dependabot_alerts_enabled_for_new_repositories= false
dependabot_security_updates_enabled_for_new_repositories = false
dependency_graph_enabled_for_new_repositories = false
secret_scanning_enabled_for_new_repositories = false
secret_scanning_push_protection_enabled_for_new_repositories = false
}`
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", "test@example.com",
),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("run with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("run with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("run with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
t.Run("updates organization settings without error", func(t *testing.T) {
billingEmail := "test1@example.com"
company := "Test Company"
blog := "https://test.com"
updatedBillingEmail := "test2@example.com"
updatedCompany := "Test Company 2"
updatedBlog := "https://test2.com"
configs := map[string]string{
"before": fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, billingEmail, company, blog),
"after": fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, updatedBillingEmail, updatedCompany, updatedBlog),
}
checks := map[string]resource.TestCheckFunc{
"before": resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", billingEmail,
),
"after": resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", updatedBillingEmail,
),
}
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: configs["before"],
Check: checks["before"],
},
{
Config: configs["after"],
Check: checks["after"],
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
t.Run("imports organization settings without error", func(t *testing.T) {
billingEmail := "test@example.com"
company := "Test Company"
blog := "https://example.com"
config := fmt.Sprintf(`
resource "github_organization_settings" "test" {
billing_email = "%s"
company = "%s"
blog = "%s"
}`, billingEmail, company, blog)
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_organization_settings.test",
"billing_email", billingEmail,
),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
{
ResourceName: "github_organization_settings.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
}