-
Notifications
You must be signed in to change notification settings - Fork 768
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 repository topics #97
Merged
Merged
Changes from 2 commits
Commits
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 |
---|---|---|
|
@@ -302,6 +302,33 @@ func TestAccGithubRepository_templates(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccGithubRepository_topics(t *testing.T) { | ||
var repo github.Repository | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
name := fmt.Sprintf("tf-acc-test-%s", randString) | ||
description := fmt.Sprintf("Terraform acceptance tests %s", randString) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckGithubRepositoryDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccGithubRepositoryConfigTopics(randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGithubRepositoryExists("github_repository.foo", &repo), | ||
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{ | ||
Name: name, | ||
Description: description, | ||
Homepage: "http://example.com/", | ||
Topics: []string{"topic1", "topic2"}, | ||
}), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
@@ -342,6 +369,7 @@ type testAccGithubRepositoryExpectedAttributes struct { | |
LicenseTemplate string | ||
GitignoreTemplate string | ||
Archived bool | ||
Topics []string | ||
} | ||
|
||
func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testAccGithubRepositoryExpectedAttributes) resource.TestCheckFunc { | ||
|
@@ -377,6 +405,9 @@ func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testA | |
if *repo.HasDownloads != want.HasDownloads { | ||
return fmt.Errorf("got has downloads %#v; want %#v", *repo.HasDownloads, want.HasDownloads) | ||
} | ||
if &repo.Topics != &want.Topics { | ||
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. You will probably need to rewrite this comparison somewhat, as the default value for a slice is if len(want.Topics) != len(repo.Topics) {
return fmt.Errorf("got has topics %#v; want %#v", repo.Topics, want.Topics)
}
for i := range want.Topics {
if repo.Topics[i] != want.Topics[i] {
return fmt.Errorf("got has topics %#v; want %#v", repo.Topics, want.Topics)
}
} |
||
return fmt.Errorf("got has topics %#v; want %#v", &repo.Topics, &want.Topics) | ||
} | ||
|
||
if *repo.DefaultBranch != want.DefaultBranch { | ||
return fmt.Errorf("got default branch %q; want %q", *repo.DefaultBranch, want.DefaultBranch) | ||
|
@@ -628,3 +659,19 @@ resource "github_repository" "foo" { | |
} | ||
`, randString, randString) | ||
} | ||
|
||
func testAccGithubRepositoryConfigTopics(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 | ||
|
||
topics = ["topic1", "topic2"] | ||
} | ||
`, randString, randString) | ||
} |
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.
This will come out of
ResourceData
as[]interface{}
, so you will need to write a simple func to "expand" this state to the SDK's representation: