Skip to content

Commit 526c9c9

Browse files
committed
Replace hard-coded TeamReviewAssignmentAlgorithm mentions
Signed-off-by: Timo Sand <[email protected]>
1 parent 77bbebd commit 526c9c9

2 files changed

Lines changed: 38 additions & 73 deletions

File tree

github/resource_github_team_settings.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1011
"github.com/shurcooL/githubv4"
1112
)
1213

@@ -44,22 +45,11 @@ func resourceGithubTeamSettings() *schema.Resource {
4445
Elem: &schema.Resource{
4546
Schema: map[string]*schema.Schema{
4647
"algorithm": {
47-
Type: schema.TypeString,
48-
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: toDiagFunc(func(v any, key string) (we []string, errs []error) {
52-
algorithm, ok := v.(string)
53-
if !ok {
54-
return nil, []error{fmt.Errorf("expected type of %s to be string", key)}
55-
}
56-
57-
if algorithm != "ROUND_ROBIN" && algorithm != "LOAD_BALANCE" {
58-
errs = append(errs, errors.New("review request delegation algorithm must be one of [\"ROUND_ROBIN\", \"LOAD_BALANCE\"]"))
59-
}
60-
61-
return we, errs
62-
}, "algorithm"),
48+
Type: schema.TypeString,
49+
Optional: true,
50+
Description: "The algorithm to use when assigning pull requests to team members. Supported values are " + string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin) + " and " + string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance) + ".",
51+
Default: string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin),
52+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin), string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)}, false)),
6353
},
6454
"member_count": {
6555
Type: schema.TypeInt,

github/resource_github_team_settings_test.go

Lines changed: 32 additions & 57 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,10 +124,8 @@ 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),
153-
ExpectError: regexp.MustCompile(`review request delegation algorithm must be one of \[.*\]`),
127+
Config: config,
128+
ExpectError: regexp.MustCompile(`expected algorithm to be one of \[.*\]`),
154129
},
155130
},
156131
})

0 commit comments

Comments
 (0)