-
Notifications
You must be signed in to change notification settings - Fork 968
Expand file tree
/
Copy pathresource_github_organization_settings_unit_test.go
More file actions
101 lines (81 loc) · 3.4 KB
/
resource_github_organization_settings_unit_test.go
File metadata and controls
101 lines (81 loc) · 3.4 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
package github
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func TestBuildOrganizationSettings_OmittedInternalReposNotSent(t *testing.T) {
resource := resourceGithubOrganizationSettings()
d := schema.TestResourceDataRaw(t, resource.Schema, map[string]any{
"billing_email": "test@example.com",
})
settings := buildOrganizationSettings(d, true)
if settings.MembersCanCreateInternalRepos != nil {
t.Error("MembersCanCreateInternalRepos should be nil when not configured")
}
}
func TestBuildOrganizationSettings_ExplicitTrueInternalReposSent(t *testing.T) {
resource := resourceGithubOrganizationSettings()
d := schema.TestResourceDataRaw(t, resource.Schema, map[string]any{
"billing_email": "test@example.com",
"members_can_create_internal_repositories": true,
})
settings := buildOrganizationSettings(d, true)
if settings.MembersCanCreateInternalRepos == nil {
t.Fatal("MembersCanCreateInternalRepos should not be nil when explicitly set to true")
}
if *settings.MembersCanCreateInternalRepos != true {
t.Errorf("MembersCanCreateInternalRepos = %v, want true", *settings.MembersCanCreateInternalRepos)
}
}
func TestBuildOrganizationSettings_ExplicitFalseInternalReposSent(t *testing.T) {
resource := resourceGithubOrganizationSettings()
d := schema.TestResourceDataRaw(t, resource.Schema, map[string]any{
"billing_email": "test@example.com",
"members_can_create_internal_repositories": false,
})
settings := buildOrganizationSettings(d, true)
if settings.MembersCanCreateInternalRepos == nil {
t.Fatal("MembersCanCreateInternalRepos should not be nil when explicitly set to false")
}
if *settings.MembersCanCreateInternalRepos != false {
t.Errorf("MembersCanCreateInternalRepos = %v, want false", *settings.MembersCanCreateInternalRepos)
}
}
func TestBuildOrganizationSettings_UpdateOmittedInternalReposNotSent(t *testing.T) {
resource := resourceGithubOrganizationSettings()
d := schema.TestResourceDataRaw(t, resource.Schema, map[string]any{
"billing_email": "test@example.com",
})
d.SetId("test-org")
settings := buildOrganizationSettings(d, true)
if settings.MembersCanCreateInternalRepos != nil {
t.Error("MembersCanCreateInternalRepos should be nil on update when field has not changed")
}
}
func TestBuildOrganizationSettings_NonEnterpriseExcludesInternalRepos(t *testing.T) {
resource := resourceGithubOrganizationSettings()
d := schema.TestResourceDataRaw(t, resource.Schema, map[string]any{
"billing_email": "test@example.com",
"members_can_create_internal_repositories": true,
})
settings := buildOrganizationSettings(d, false)
if settings.MembersCanCreateInternalRepos != nil {
t.Error("MembersCanCreateInternalRepos should be nil when not enterprise")
}
}
func TestOrganizationSettingsSchemaInternalRepos(t *testing.T) {
resource := resourceGithubOrganizationSettings()
field := resource.Schema["members_can_create_internal_repositories"]
if field == nil {
t.Fatal("members_can_create_internal_repositories not found in schema")
}
if !field.Optional {
t.Error("members_can_create_internal_repositories should be Optional")
}
if !field.Computed {
t.Error("members_can_create_internal_repositories should be Computed")
}
if field.Default != nil {
t.Errorf("members_can_create_internal_repositories should have no Default, got %v", field.Default)
}
}