Skip to content

Commit e389464

Browse files
committed
Replace hard-coded TeamReviewAssignmentAlgorithm mentions
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 3af0ce0 commit e389464

2 files changed

Lines changed: 34 additions & 59 deletions

File tree

github/resource_github_team_settings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func resourceGithubTeamSettings() *schema.Resource {
4646
"algorithm": {
4747
Type: schema.TypeString,
4848
Optional: true,
49-
Description: "The algorithm to use when assigning pull requests to team members. Supported values are 'ROUND_ROBIN' and 'LOAD_BALANCE'.",
50-
Default: "ROUND_ROBIN",
51-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"ROUND_ROBIN", "LOAD_BALANCE"}, false)),
49+
Description: "The algorithm to use when assigning pull requests to team members. Supported values are " + string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin) + " and " + string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance) + ".",
50+
Default: string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin),
51+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin), string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)}, false)),
5252
},
5353
"member_count": {
5454
Type: schema.TypeInt,

github/resource_github_team_settings_test.go

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/shurcooL/githubv4"
1112
)
1213

1314
func TestAccGithubTeamSettings(t *testing.T) {
@@ -25,23 +26,23 @@ func TestAccGithubTeamSettings(t *testing.T) {
2526
}
2627
`, teamName)
2728

28-
check := resource.ComposeTestCheckFunc(
29-
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
30-
)
31-
3229
resource.Test(t, resource.TestCase{
3330
PreCheck: func() { skipUnlessHasOrgs(t) },
3431
ProviderFactories: providerFactories,
3532
Steps: []resource.TestStep{
3633
{
3734
Config: config,
38-
Check: check,
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
37+
),
3938
},
4039
{
4140
Config: strings.Replace(config,
4241
`github_team.test.id`,
4342
`github_team.test.slug`, 1),
44-
Check: check,
43+
Check: resource.ComposeTestCheckFunc(
44+
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
45+
),
4546
},
4647
},
4748
})
@@ -50,7 +51,8 @@ func TestAccGithubTeamSettings(t *testing.T) {
5051
t.Run("manages team code review settings", func(t *testing.T) {
5152
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
5253
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
53-
config := fmt.Sprintf(`
54+
testAlgorithm := githubv4.TeamReviewAssignmentAlgorithmRoundRobin
55+
config := `
5456
resource "github_team" "test" {
5557
name = "%s"
5658
description = "generated by terraform provider automated testing"
@@ -59,65 +61,40 @@ func TestAccGithubTeamSettings(t *testing.T) {
5961
resource "github_team_settings" "test" {
6062
team_id = "${github_team.test.id}"
6163
review_request_delegation {
62-
algorithm = "ROUND_ROBIN"
63-
member_count = 1
64-
notify = true
64+
algorithm = "%s"
65+
member_count = %d
66+
notify = %t
6567
}
6668
}
67-
`, teamName)
68-
69-
checks := map[string]resource.TestCheckFunc{
70-
"round_robin": resource.ComposeTestCheckFunc(
71-
resource.TestCheckResourceAttr(
72-
"github_team_settings.test", "review_request_delegation.0.algorithm",
73-
"ROUND_ROBIN",
74-
),
75-
),
76-
"load_balance": resource.ComposeTestCheckFunc(
77-
resource.TestCheckResourceAttr(
78-
"github_team_settings.test", "review_request_delegation.0.algorithm",
79-
"LOAD_BALANCE",
80-
),
81-
),
82-
"review_count": resource.ComposeTestCheckFunc(
83-
resource.TestCheckResourceAttr(
84-
"github_team_settings.test", "review_request_delegation.0.member_count",
85-
"3",
86-
),
87-
),
88-
"notify": resource.ComposeTestCheckFunc(
89-
resource.TestCheckResourceAttr(
90-
"github_team_settings.test", "review_request_delegation.0.notify",
91-
"false",
92-
),
93-
),
94-
}
69+
`
9570

9671
resource.Test(t, resource.TestCase{
9772
PreCheck: func() { skipUnlessHasOrgs(t) },
9873
ProviderFactories: providerFactories,
9974
Steps: []resource.TestStep{
10075
{
101-
Config: config,
102-
Check: checks["round_robin"],
76+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 1, true),
77+
Check: resource.ComposeTestCheckFunc(
78+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(testAlgorithm)),
79+
),
10380
},
10481
{
105-
Config: strings.Replace(config,
106-
`algorithm = "ROUND_ROBIN"`,
107-
`algorithm = "LOAD_BALANCE"`, 1),
108-
Check: checks["load_balance"],
82+
Config: fmt.Sprintf(config, teamName, githubv4.TeamReviewAssignmentAlgorithmLoadBalance, 1, true),
83+
Check: resource.ComposeTestCheckFunc(
84+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)),
85+
),
10986
},
11087
{
111-
Config: strings.Replace(config,
112-
`member_count = 1`,
113-
`member_count = 3`, 1),
114-
Check: checks["review_count"],
88+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, true),
89+
Check: resource.ComposeTestCheckFunc(
90+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.member_count", "3"),
91+
),
11592
},
11693
{
117-
Config: strings.Replace(config,
118-
`notify = true`,
119-
`notify = false`, 1),
120-
Check: checks["notify"],
94+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, false),
95+
Check: resource.ComposeTestCheckFunc(
96+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.notify", "false"),
97+
),
12198
},
12299
},
123100
})
@@ -135,7 +112,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
135112
resource "github_team_settings" "test" {
136113
team_id = "${github_team.test.id}"
137114
review_request_delegation {
138-
algorithm = "ROUND_ROBIN"
115+
algorithm = "invalid"
139116
member_count = 1
140117
notify = true
141118
}
@@ -147,9 +124,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
147124
ProviderFactories: providerFactories,
148125
Steps: []resource.TestStep{
149126
{
150-
Config: strings.Replace(config,
151-
`algorithm = "ROUND_ROBIN"`,
152-
`algorithm = "invalid"`, 1),
127+
Config: config,
153128
ExpectError: regexp.MustCompile(`expected algorithm to be one of \[.*\]`),
154129
},
155130
},

0 commit comments

Comments
 (0)