-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vulnerability_alerts attribute for repositories #444
Merged
jcudit
merged 8 commits into
integrations:master
from
jtsaito:repo-vulnerability-alerts
Sep 18, 2020
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7dd7b9d
Add vulnerability_alerts attribute for repositories
jtsaito 244f079
Check change of vulnerability alerts only if new resource
jtsaito 11651f6
No default value for vulnerability alerts
jtsaito c4916dd
Remove redundant test code
jtsaito 059fa1e
Update website on repository vulnerability alerts
jtsaito cb87733
Merge branch 'master' into repo-vulnerability-alerts
f71e18f
Add newline
40b17dc
Update website/docs/r/repository.html.markdown
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ func TestAccGithubRepository_basic(t *testing.T) { | |
DefaultBranch: "master", | ||
Archived: false, | ||
}), | ||
testAccCheckGithubVulnerabilityAlerts(rn, false), | ||
), | ||
}, | ||
{ | ||
|
@@ -101,6 +102,7 @@ func TestAccGithubRepository_basic(t *testing.T) { | |
HasProjects: false, | ||
Archived: false, | ||
}), | ||
testAccCheckGithubVulnerabilityAlerts(rn, false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar comment as above |
||
), | ||
}, | ||
{ | ||
|
@@ -523,6 +525,78 @@ func TestAccGithubRepository_createFromTemplate(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccGithubRepository_vulnerabilityAlerts(t *testing.T) { | ||
var repo github.Repository | ||
|
||
rn := "github_repository.foo" | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
name := fmt.Sprintf("tf-acc-test-%s", randString) | ||
description := fmt.Sprintf("Terraform acceptance tests %s", randString) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckGithubRepositoryDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccGithubRepositoryVulnerabilityAlertsConfig(randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGithubRepositoryExists(rn, &repo), | ||
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{ | ||
Name: name, | ||
Description: description, | ||
Homepage: "http://example.com/", | ||
HasIssues: true, | ||
HasWiki: true, | ||
IsTemplate: false, | ||
AllowMergeCommit: true, | ||
AllowSquashMerge: false, | ||
AllowRebaseMerge: false, | ||
DeleteBranchOnMerge: false, | ||
HasDownloads: true, | ||
HasProjects: false, | ||
DefaultBranch: "master", | ||
Archived: false, | ||
}), | ||
testAccCheckGithubVulnerabilityAlerts(rn, true), | ||
), | ||
}, | ||
{ | ||
Config: testAccGithubRepositoryVulnerabilityAlertsUpdateConfig(randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGithubRepositoryExists(rn, &repo), | ||
|
||
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{ | ||
Name: name, | ||
Description: description, | ||
Homepage: "http://example.com/", | ||
HasIssues: true, | ||
HasWiki: true, | ||
IsTemplate: false, | ||
AllowMergeCommit: true, | ||
AllowSquashMerge: false, | ||
AllowRebaseMerge: false, | ||
DeleteBranchOnMerge: false, | ||
HasDownloads: true, | ||
HasProjects: false, | ||
DefaultBranch: "master", | ||
Archived: false, | ||
}), | ||
testAccCheckGithubVulnerabilityAlerts(rn, false), | ||
), | ||
}, | ||
{ | ||
ResourceName: rn, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"auto_init", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
@@ -557,6 +631,23 @@ func testAccCheckGithubRepositoryTemplateRepoAttribute(n string, repo *github.Re | |
} | ||
} | ||
|
||
func testAccCheckGithubVulnerabilityAlerts(n string, expected bool) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
org := testAccProvider.Meta().(*Organization) | ||
conn := org.v3client | ||
actual, _, err := conn.Repositories.GetVulnerabilityAlerts(context.TODO(), org.name, n) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if expected != actual { | ||
return fmt.Errorf("Unexpected vulnerability alerts, got: %t", actual) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
type testAccGithubRepositoryExpectedAttributes struct { | ||
Name string | ||
Description string | ||
|
@@ -965,3 +1056,53 @@ resource "github_branch_protection" "repo_name_master" { | |
} | ||
`, randString) | ||
} | ||
|
||
func testAccGithubRepositoryVulnerabilityAlertsConfig(randString string) string { | ||
return fmt.Sprintf(` | ||
resource "github_repository" "foo" { | ||
name = "tf-acc-test-%s" | ||
description = "Terraform acceptance tests %s" | ||
homepage_url = "http://example.com/" | ||
|
||
# So that acceptance tests can be run in a github organization | ||
# with no billing | ||
private = false | ||
|
||
has_issues = true | ||
has_wiki = true | ||
is_template = false | ||
allow_merge_commit = true | ||
allow_squash_merge = false | ||
allow_rebase_merge = false | ||
has_downloads = true | ||
auto_init = false | ||
|
||
vulnerability_alerts = true | ||
} | ||
`, randString, randString) | ||
} | ||
|
||
func testAccGithubRepositoryVulnerabilityAlertsUpdateConfig(randString string) string { | ||
return fmt.Sprintf(` | ||
resource "github_repository" "foo" { | ||
name = "tf-acc-test-%s" | ||
description = "Terraform acceptance tests %s" | ||
homepage_url = "http://example.com/" | ||
|
||
# So that acceptance tests can be run in a github organization | ||
# with no billing | ||
private = false | ||
|
||
has_issues = true | ||
has_wiki = true | ||
is_template = false | ||
allow_merge_commit = true | ||
allow_squash_merge = false | ||
allow_rebase_merge = false | ||
has_downloads = true | ||
auto_init = false | ||
|
||
vulnerability_alerts = false | ||
} | ||
`, randString, randString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in calls to
testAccCheckGithubVulnerabilityAlerts
, we'll want to send the repo name (in this case stored in therepo
variable) as needed for the github API method; alternatively you could pass the wholerepo
object and extract the name inside thetestAccCheckGithubVulnerabilityAlerts
method