Skip to content

Commit 2cd04ec

Browse files
refactor: use constants for field names and testResourcePrefix in tests
1 parent e10c3cc commit 2cd04ec

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

github/data_source_github_enterprise_team_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAccGithubEnterpriseTeamOrganizationsDataSource(t *testing.T) {
6262
6363
resource "github_enterprise_team" "test" {
6464
enterprise_slug = data.github_enterprise.enterprise.slug
65-
name = "tf-acc-ds-team-orgs-%s"
65+
name = "%s%s"
6666
organization_selection_type = "selected"
6767
}
6868
@@ -77,7 +77,7 @@ func TestAccGithubEnterpriseTeamOrganizationsDataSource(t *testing.T) {
7777
enterprise_team = github_enterprise_team.test.slug
7878
depends_on = [github_enterprise_team_organizations.assign]
7979
}
80-
`, testAccConf.enterpriseSlug, randomID, testAccConf.owner)
80+
`, testAccConf.enterpriseSlug, testResourcePrefix, randomID, testAccConf.owner)
8181

8282
resource.Test(t, resource.TestCase{
8383
PreCheck: func() { skipUnlessEnterprise(t) },
@@ -106,7 +106,7 @@ func TestAccGithubEnterpriseTeamMembershipDataSource(t *testing.T) {
106106
107107
resource "github_enterprise_team" "test" {
108108
enterprise_slug = data.github_enterprise.enterprise.slug
109-
name = "tf-acc-ds-team-member-%s"
109+
name = "%s%s"
110110
}
111111
112112
resource "github_enterprise_team_membership" "test" {
@@ -121,7 +121,7 @@ func TestAccGithubEnterpriseTeamMembershipDataSource(t *testing.T) {
121121
username = "%s"
122122
depends_on = [github_enterprise_team_membership.test]
123123
}
124-
`, testAccConf.enterpriseSlug, randomID, username, username)
124+
`, testAccConf.enterpriseSlug, testResourcePrefix, randomID, username, username)
125125

126126
resource.Test(t, resource.TestCase{
127127
PreCheck: func() { skipUnlessEnterprise(t) },

github/data_source_github_enterprise_teams.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1111
)
1212

13+
const (
14+
teamIDKey = "team_id"
15+
teamSlugKey = "slug"
16+
teamNameKey = "name"
17+
teamDescriptionKey = "description"
18+
teamOrganizationSelectionKey = "organization_selection_type"
19+
teamGroupIDKey = "group_id"
20+
)
21+
1322
func dataSourceGithubEnterpriseTeams() *schema.Resource {
1423
return &schema.Resource{
1524
Description: "Lists all GitHub enterprise teams in an enterprise.",
@@ -28,32 +37,32 @@ func dataSourceGithubEnterpriseTeams() *schema.Resource {
2837
Description: "All teams in the enterprise.",
2938
Elem: &schema.Resource{
3039
Schema: map[string]*schema.Schema{
31-
"team_id": {
40+
teamIDKey: {
3241
Type: schema.TypeInt,
3342
Computed: true,
3443
Description: "The numeric ID of the enterprise team.",
3544
},
36-
"slug": {
45+
teamSlugKey: {
3746
Type: schema.TypeString,
3847
Computed: true,
3948
Description: "The slug of the enterprise team.",
4049
},
41-
"name": {
50+
teamNameKey: {
4251
Type: schema.TypeString,
4352
Computed: true,
4453
Description: "The name of the enterprise team.",
4554
},
46-
"description": {
55+
teamDescriptionKey: {
4756
Type: schema.TypeString,
4857
Computed: true,
4958
Description: "A description of the enterprise team.",
5059
},
51-
"organization_selection_type": {
60+
teamOrganizationSelectionKey: {
5261
Type: schema.TypeString,
5362
Computed: true,
5463
Description: "Specifies which organizations in the enterprise should have access to this team.",
5564
},
56-
"group_id": {
65+
teamGroupIDKey: {
5766
Type: schema.TypeString,
5867
Computed: true,
5968
Description: "The ID of the IdP group to assign team membership with.",
@@ -76,14 +85,14 @@ func dataSourceGithubEnterpriseTeamsRead(ctx context.Context, d *schema.Resource
7685
flat := make([]any, 0, len(teams))
7786
for _, t := range teams {
7887
m := map[string]any{
79-
"team_id": int(t.ID),
80-
"slug": t.Slug,
81-
"name": t.Name,
88+
teamIDKey: int(t.ID),
89+
teamSlugKey: t.Slug,
90+
teamNameKey: t.Name,
8291
}
8392
if t.Description != nil {
84-
m["description"] = *t.Description
93+
m[teamDescriptionKey] = *t.Description
8594
} else {
86-
m["description"] = ""
95+
m[teamDescriptionKey] = ""
8796
}
8897
orgSel := ""
8998
if t.OrganizationSelectionType != nil {
@@ -92,11 +101,11 @@ func dataSourceGithubEnterpriseTeamsRead(ctx context.Context, d *schema.Resource
92101
if orgSel == "" {
93102
orgSel = "disabled"
94103
}
95-
m["organization_selection_type"] = orgSel
104+
m[teamOrganizationSelectionKey] = orgSel
96105
if t.GroupID != "" {
97-
m["group_id"] = t.GroupID
106+
m[teamGroupIDKey] = t.GroupID
98107
} else {
99-
m["group_id"] = ""
108+
m[teamGroupIDKey] = ""
100109
}
101110
flat = append(flat, m)
102111
}

0 commit comments

Comments
 (0)