Skip to content

Commit 989ca6b

Browse files
pippittnickfloyd
andauthored
fix(resource/github_organization_custom_properties): allow for import (#2834)
renamed file to match others add some testing Co-authored-by: Nick Floyd <[email protected]>
1 parent 2008dfd commit 989ca6b

File tree

2 files changed

+159
-1
lines changed

2 files changed

+159
-1
lines changed

github/resource_github_organisation_custom_properties.go renamed to github/resource_github_organization_custom_properties.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ func resourceGithubCustomPropertiesDelete(d *schema.ResourceData, meta interface
136136
}
137137

138138
func resourceGithubCustomPropertiesImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
139-
// WIP
139+
if err := d.Set("property_name", d.Id()); err != nil {
140+
return nil, err
141+
}
140142
return []*schema.ResourceData{d}, nil
141143
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package github
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccGithubOrganizationCustomProperties(t *testing.T) {
11+
t.Run("creates custom property without error", func(t *testing.T) {
12+
13+
config := `
14+
resource "github_organization_custom_properties" "test" {
15+
allowed_values = [ "Test" ]
16+
description = "Test Description"
17+
default_value = "Test"
18+
property_name = "Test"
19+
required = true
20+
value_type = "single_select"
21+
}`
22+
23+
check := resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttr(
25+
"github_organization_custom_properties.test",
26+
"property_name", "Test",
27+
),
28+
)
29+
testCase := func(t *testing.T, mode string) {
30+
resource.Test(t, resource.TestCase{
31+
PreCheck: func() { skipUnlessMode(t, mode) },
32+
Providers: testAccProviders,
33+
Steps: []resource.TestStep{
34+
{
35+
Config: config,
36+
Check: check,
37+
},
38+
},
39+
})
40+
}
41+
t.Run("run with an anonymous account", func(t *testing.T) {
42+
t.Skip("anonymous account not supported for this operation")
43+
})
44+
t.Run("run with an individual account", func(t *testing.T) {
45+
t.Skip("individual account not supported for this operation")
46+
})
47+
t.Run("run with an organization account", func(t *testing.T) {
48+
testCase(t, organization)
49+
})
50+
51+
})
52+
t.Run("create custom property and update them", func(t *testing.T) {
53+
configBefore := `
54+
resource "github_organization_custom_properties" "test" {
55+
allowed_values = ["one"]
56+
description = "Test Description"
57+
property_name = "Test"
58+
value_type = "single_select"
59+
}`
60+
61+
configAfter := `
62+
resource "github_organization_custom_properties" "test" {
63+
allowed_values = ["one", "two"]
64+
description = "Test Description 2"
65+
property_name = "Test"
66+
value_type = "single_select"
67+
}`
68+
69+
const resourceName = "github_organization_custom_properties.test"
70+
71+
checkBefore := resource.ComposeTestCheckFunc(
72+
resource.TestCheckResourceAttr(resourceName, "allowed_values.#", "1"),
73+
)
74+
checkAfter := resource.ComposeTestCheckFunc(
75+
resource.TestCheckResourceAttr(resourceName, "allowed_values.#", "2"),
76+
)
77+
78+
testCase := func(t *testing.T, mode string) {
79+
resource.Test(t, resource.TestCase{
80+
PreCheck: func() { skipUnlessMode(t, mode) },
81+
Providers: testAccProviders,
82+
Steps: []resource.TestStep{
83+
{
84+
Config: configBefore,
85+
Check: checkBefore,
86+
},
87+
{
88+
Config: configAfter,
89+
Check: checkAfter,
90+
},
91+
},
92+
})
93+
}
94+
95+
t.Run("with an anonymous account", func(t *testing.T) {
96+
t.Skip("anonymous account not supported for this operation")
97+
})
98+
99+
t.Run("with an individual account", func(t *testing.T) {
100+
t.Skip("individual account not supported for this operation")
101+
})
102+
103+
t.Run("with an organization account", func(t *testing.T) {
104+
testCase(t, organization)
105+
})
106+
})
107+
108+
t.Run("imports organization custom property without error", func(t *testing.T) {
109+
description := "Test Description Import"
110+
propertyName := "Test"
111+
valueType := "string"
112+
113+
config := fmt.Sprintf(`
114+
resource "github_organization_custom_properties" "test" {
115+
description = "%s"
116+
property_name = "%s"
117+
value_type = "%s"
118+
}`, description, propertyName, valueType)
119+
120+
check := resource.ComposeTestCheckFunc(
121+
resource.TestCheckResourceAttr(
122+
"github_organization_custom_properties.test",
123+
"description", description,
124+
),
125+
)
126+
127+
testCase := func(t *testing.T, mode string) {
128+
resource.Test(t, resource.TestCase{
129+
PreCheck: func() { skipUnlessMode(t, mode) },
130+
Providers: testAccProviders,
131+
Steps: []resource.TestStep{
132+
{
133+
Config: config,
134+
Check: check,
135+
},
136+
{
137+
ResourceName: "github_organization_custom_properties.test",
138+
ImportState: true,
139+
ImportStateVerify: true,
140+
},
141+
},
142+
})
143+
}
144+
t.Run("with an anonymous account", func(t *testing.T) {
145+
t.Skip("anonymous account not supported for this operation")
146+
})
147+
148+
t.Run("with an individual account", func(t *testing.T) {
149+
t.Skip("individual account not supported for this operation")
150+
})
151+
152+
t.Run("with an organization account", func(t *testing.T) {
153+
testCase(t, organization)
154+
})
155+
})
156+
}

0 commit comments

Comments
 (0)