@@ -2026,6 +2026,172 @@ func TestAccGithubRepository_fork(t *testing.T) {
20262026 })
20272027}
20282028
2029+ func TestAccRepository_VulnerabilityAlerts (t * testing.T ) {
2030+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
2031+
2032+ t .Run ("can enable vulnerability alerts" , func (t * testing.T ) {
2033+ config := fmt .Sprintf (`
2034+ resource "github_repository" "test" {
2035+ name = "tf-acc-test-vuln-%s"
2036+ description = "Terraform acceptance test - repository %[1]s"
2037+ vulnerability_alerts = true
2038+ }
2039+ ` , randomID )
2040+
2041+ testCase := func (t * testing.T , mode string ) {
2042+ resource .Test (t , resource.TestCase {
2043+ PreCheck : func () { skipUnlessMode (t , mode ) },
2044+ Providers : testAccProviders ,
2045+ Steps : []resource.TestStep {
2046+ {
2047+ Config : config ,
2048+ Check : resource .ComposeTestCheckFunc (
2049+ resource .TestCheckResourceAttr (
2050+ "github_repository.test" , "vulnerability_alerts" ,
2051+ "true" ,
2052+ ),
2053+ ),
2054+ },
2055+ },
2056+ })
2057+ }
2058+
2059+ t .Run ("with an individual account" , func (t * testing.T ) {
2060+ testCase (t , individual )
2061+ })
2062+
2063+ t .Run ("with an organization account" , func (t * testing.T ) {
2064+ testCase (t , organization )
2065+ })
2066+
2067+ t .Run ("with an anonymous account" , func (t * testing.T ) {
2068+ t .Skip ("anonymous account not supported for this operation" )
2069+ })
2070+ })
2071+ t .Run ("sets vulnerability alerts to false when not set in config" , func (t * testing.T ) {
2072+ config := fmt .Sprintf (`
2073+ resource "github_repository" "test" {
2074+ name = "tf-acc-test-vuln-%s"
2075+ description = "Terraform acceptance test - repository %[1]s"
2076+ }
2077+ ` , randomID )
2078+
2079+ testCase := func (t * testing.T , mode string ) {
2080+ resource .Test (t , resource.TestCase {
2081+ PreCheck : func () { skipUnlessMode (t , mode ) },
2082+ Providers : testAccProviders ,
2083+ Steps : []resource.TestStep {
2084+ {
2085+ Config : config ,
2086+ Check : resource .ComposeAggregateTestCheckFunc (
2087+ resource .TestCheckResourceAttr (
2088+ "github_repository.test" , "vulnerability_alerts" , "false" ,
2089+ ),
2090+ ),
2091+ },
2092+ },
2093+ })
2094+ }
2095+
2096+ t .Run ("with an individual account" , func (t * testing.T ) {
2097+ testCase (t , individual )
2098+ })
2099+
2100+ t .Run ("with an organization account" , func (t * testing.T ) {
2101+ testCase (t , organization )
2102+ })
2103+
2104+ t .Run ("with an anonymous account" , func (t * testing.T ) {
2105+ t .Skip ("anonymous account not supported for this operation" )
2106+ })
2107+ })
2108+ t .Run ("can disable vulnerability alerts" , func (t * testing.T ) {
2109+ config := fmt .Sprintf (`
2110+ resource "github_repository" "test" {
2111+ name = "tf-acc-test-vuln-%s"
2112+ description = "Terraform acceptance test - repository %[1]s"
2113+ vulnerability_alerts = false
2114+ }
2115+ ` , randomID )
2116+
2117+ testCase := func (t * testing.T , mode string ) {
2118+ resource .Test (t , resource.TestCase {
2119+ PreCheck : func () { skipUnlessMode (t , mode ) },
2120+ Providers : testAccProviders ,
2121+ Steps : []resource.TestStep {
2122+ {
2123+ Config : config ,
2124+ Check : resource .ComposeTestCheckFunc (
2125+ resource .TestCheckResourceAttr (
2126+ "github_repository.test" , "vulnerability_alerts" ,
2127+ "false" ,
2128+ ),
2129+ ),
2130+ },
2131+ },
2132+ })
2133+ }
2134+
2135+ t .Run ("with an individual account" , func (t * testing.T ) {
2136+ testCase (t , individual )
2137+ })
2138+
2139+ t .Run ("with an organization account" , func (t * testing.T ) {
2140+ testCase (t , organization )
2141+ })
2142+
2143+ t .Run ("with an anonymous account" , func (t * testing.T ) {
2144+ t .Skip ("anonymous account not supported for this operation" )
2145+ })
2146+ })
2147+ t .Run ("can modify vulnerability alerts" , func (t * testing.T ) {
2148+ config := fmt .Sprintf (`
2149+ resource "github_repository" "test" {
2150+ name = "tf-acc-test-vuln-%s"
2151+ description = "Terraform acceptance test - repository %[1]s"
2152+ vulnerability_alerts = false
2153+ }
2154+ ` , randomID )
2155+
2156+ testCase := func (t * testing.T , mode string ) {
2157+ resource .Test (t , resource.TestCase {
2158+ PreCheck : func () { skipUnlessMode (t , mode ) },
2159+ Providers : testAccProviders ,
2160+ Steps : []resource.TestStep {
2161+ {
2162+ Config : config ,
2163+ Check : resource .ComposeTestCheckFunc (
2164+ resource .TestCheckResourceAttr (
2165+ "github_repository.test" , "vulnerability_alerts" , "false" ,
2166+ ),
2167+ ),
2168+ },
2169+ {
2170+ Config : strings .Replace (config , "vulnerability_alerts = false" , "vulnerability_alerts = true" , 1 ),
2171+ Check : resource .ComposeTestCheckFunc (
2172+ resource .TestCheckResourceAttr (
2173+ "github_repository.test" , "vulnerability_alerts" , "true" ,
2174+ ),
2175+ ),
2176+ },
2177+ },
2178+ })
2179+ }
2180+
2181+ t .Run ("with an individual account" , func (t * testing.T ) {
2182+ testCase (t , individual )
2183+ })
2184+
2185+ t .Run ("with an organization account" , func (t * testing.T ) {
2186+ testCase (t , organization )
2187+ })
2188+
2189+ t .Run ("with an anonymous account" , func (t * testing.T ) {
2190+ t .Skip ("anonymous account not supported for this operation" )
2191+ })
2192+ })
2193+ }
2194+
20292195func createForkedRepository (repositoryName string ) error {
20302196 baseURL , isGHES , err := getBaseURL (os .Getenv ("GITHUB_BASE_URL" ))
20312197 if err != nil {
0 commit comments