Skip to content

Commit 02a312a

Browse files
Add tests for team notification_setting field
- Add resource tests covering default, enabled, and disabled notification settings - Add data source tests verifying notification_setting is properly exposed - Include update scenarios to test field mutability
1 parent 587b662 commit 02a312a

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

github/data_source_github_team_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,60 @@ func TestAccGithubTeamDataSource(t *testing.T) {
228228

229229
})
230230

231+
t.Run("queries teams with notification settings", func(t *testing.T) {
232+
233+
config := fmt.Sprintf(`
234+
resource "github_team" "test_enabled" {
235+
name = "tf-acc-test-enabled-%s"
236+
notification_setting = "notifications_enabled"
237+
}
238+
239+
resource "github_team" "test_disabled" {
240+
name = "tf-acc-test-disabled-%s"
241+
notification_setting = "notifications_disabled"
242+
}
243+
244+
data "github_team" "test_enabled" {
245+
slug = github_team.test_enabled.slug
246+
}
247+
248+
data "github_team" "test_disabled" {
249+
slug = github_team.test_disabled.slug
250+
}
251+
`, randomID, randomID)
252+
253+
check := resource.ComposeAggregateTestCheckFunc(
254+
resource.TestCheckResourceAttr("data.github_team.test_enabled", "notification_setting", "notifications_enabled"),
255+
resource.TestCheckResourceAttr("data.github_team.test_disabled", "notification_setting", "notifications_disabled"),
256+
)
257+
258+
testCase := func(t *testing.T, mode string) {
259+
resource.Test(t, resource.TestCase{
260+
PreCheck: func() { skipUnlessMode(t, mode) },
261+
Providers: testAccProviders,
262+
Steps: []resource.TestStep{
263+
{
264+
Config: config,
265+
Check: check,
266+
},
267+
},
268+
})
269+
}
270+
271+
t.Run("with an anonymous account", func(t *testing.T) {
272+
t.Skip("anonymous account not supported for this operation")
273+
})
274+
275+
t.Run("with an individual account", func(t *testing.T) {
276+
t.Skip("individual account not supported for this operation")
277+
})
278+
279+
t.Run("with an organization account", func(t *testing.T) {
280+
testCase(t, organization)
281+
})
282+
283+
})
284+
231285
t.Run("queries an existing team with connected repositories", func(t *testing.T) {
232286

233287
config := fmt.Sprintf(`

github/resource_github_team_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,83 @@ func TestAccGithubTeamRemovesDefaultMaintainer(t *testing.T) {
193193

194194
}
195195

196+
func TestAccGithubTeamNotificationSetting(t *testing.T) {
197+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
198+
199+
t.Run("creates teams with different notification settings", func(t *testing.T) {
200+
201+
config := fmt.Sprintf(`
202+
resource "github_team" "test_default" {
203+
name = "tf-acc-default-%s"
204+
}
205+
206+
resource "github_team" "test_enabled" {
207+
name = "tf-acc-enabled-%s"
208+
notification_setting = "notifications_enabled"
209+
}
210+
211+
resource "github_team" "test_disabled" {
212+
name = "tf-acc-disabled-%s"
213+
notification_setting = "notifications_disabled"
214+
}
215+
`, randomID, randomID, randomID)
216+
217+
configUpdated := fmt.Sprintf(`
218+
resource "github_team" "test_default" {
219+
name = "tf-acc-default-%s"
220+
}
221+
222+
resource "github_team" "test_enabled" {
223+
name = "tf-acc-enabled-%s"
224+
notification_setting = "notifications_disabled"
225+
}
226+
227+
resource "github_team" "test_disabled" {
228+
name = "tf-acc-disabled-%s"
229+
notification_setting = "notifications_enabled"
230+
}
231+
`, randomID, randomID, randomID)
232+
233+
testCase := func(t *testing.T, mode string) {
234+
resource.Test(t, resource.TestCase{
235+
PreCheck: func() { skipUnlessMode(t, mode) },
236+
Providers: testAccProviders,
237+
Steps: []resource.TestStep{
238+
{
239+
Config: config,
240+
Check: resource.ComposeTestCheckFunc(
241+
resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"),
242+
resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_enabled"),
243+
resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_disabled"),
244+
),
245+
},
246+
{
247+
Config: configUpdated,
248+
Check: resource.ComposeTestCheckFunc(
249+
resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"),
250+
resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_disabled"),
251+
resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_enabled"),
252+
),
253+
},
254+
},
255+
})
256+
}
257+
258+
t.Run("with an anonymous account", func(t *testing.T) {
259+
t.Skip("anonymous account not supported for this operation")
260+
})
261+
262+
t.Run("with an individual account", func(t *testing.T) {
263+
t.Skip("individual account not supported for this operation")
264+
})
265+
266+
t.Run("with an organization account", func(t *testing.T) {
267+
testCase(t, organization)
268+
})
269+
270+
})
271+
}
272+
196273
func TestAccGithubTeamUpdateName(t *testing.T) {
197274
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
198275

0 commit comments

Comments
 (0)