Skip to content
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

GH-144 - New Data Source: Github release #356

Merged
merged 10 commits into from
Feb 20, 2020
Merged

GH-144 - New Data Source: Github release #356

merged 10 commits into from
Feb 20, 2020

Conversation

benj-fletch
Copy link
Contributor

This PR covers functionality described in GH-144.

The following functionality has been provided by this new data source:

Things not covered by this data source:

The following constraints apply to this data source:

Required properties:

  • repository : Name of the repository to retrieve the release from
  • owner : Owner of the repository (can be org / user)
  • retrieve_by : Describes how to fetch the release. Valid values are id, tag, latest
  • release_id : ID of the release to retrieve. Must be specified when retrieve_by = id
  • release_tag : Tag of the release to retrieve. Must be specified when retrieve_by = tag

I would like to say that this is my first real foray with Go, so any styling / syntax / best practice tips would be appreciated!

@ghost ghost added the size/XL label Feb 14, 2020
@benj-fletch benj-fletch changed the title GH-144 - New resource: Github release GH-144 - New Data Source: Github release Feb 14, 2020
@ghost ghost added the Type: Documentation Improvements or additions to documentation label Feb 14, 2020
Copy link
Contributor

@jcudit jcudit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good and is nearing the finish line. See my comment inline around fixes to TestAccGithubReleaseDataSource_fetchByTagExisting.

Comment on lines 43 to 44
resource.TestMatchResourceAttr("data.github_release.test", "url", regexp.MustCompile(`hashicorp/terraform`)),
resource.TestMatchResourceAttr("data.github_release.test", "tarball_url", regexp.MustCompile(`hashicorp/terraform/tarball`)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: to keep this within some margins, I would extract the third arguments here into their own variables above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout, will update this.

Steps: []resource.TestStep{
{
Config: testAccCheckGithubReleaseDataSourceConfig("", "", retrieveBy, "", 0),
ExpectError: regexp.MustCompile("release_id` must be set when `retrieve_by` = `id`"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a leading character here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll add that in

Comment on lines 110 to 131
func TestAccGithubReleaseDataSource_fetchByTagExisting(t *testing.T) {
repo := "terraform"
owner := "hashicorp"
retrieveBy := "tag"
tag := "v0.12.20"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGithubReleaseDataSourceConfig(repo, owner, retrieveBy, tag, 0),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.github_release.test", "release_tag", tag),
resource.TestMatchResourceAttr("data.github_release.test", "url", regexp.MustCompile(`hashicorp/terraform`)),
resource.TestMatchResourceAttr("data.github_release.test", "tarball_url", regexp.MustCompile(`hashicorp/terraform/tarball`)),
),
},
},
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention within this repository I've observed so far has been to not hard-code values such as the repository and tag as was done in this test. I think this test is stable but would like to see an attempt to obtain these values from the environment before proceeding with the hard-coded defaults. See here for prior art.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for referring to this. I was unsure how to proceed since we don't have an associated resource to create / delete a release. Have a look at my changes - adding another environment variable with the tag and sourcing it from the template repo.

In future, if added, I think it would be good to manage this release test object via a release resource as well, making it fully isolated.

@jcudit
Copy link
Contributor

jcudit commented Feb 18, 2020

Tests are passing:

2020-02-18T14:50:03.2678040Z ok  	github.com/terraform-providers/terraform-provider-github/github	9.025s
2020-02-18T14:50:04.0971855Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:06.0602549Z === RUN   TestAccGithubReleaseDataSource_fetchByLatestNoReleaseReturnsError
2020-02-18T14:50:06.0602847Z === PAUSE TestAccGithubReleaseDataSource_fetchByLatestNoReleaseReturnsError
2020-02-18T14:50:06.0603013Z === CONT  TestAccGithubReleaseDataSource_fetchByLatestNoReleaseReturnsError
2020-02-18T14:50:06.0603803Z --- PASS: TestAccGithubReleaseDataSource_fetchByLatestNoReleaseReturnsError (0.14s)
2020-02-18T14:50:06.0603964Z PASS
2020-02-18T14:50:06.0604311Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.153s
2020-02-18T14:50:06.8717167Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:09.2337581Z === RUN   TestAccGithubReleaseDataSource_latestExisting
2020-02-18T14:50:09.2338225Z === PAUSE TestAccGithubReleaseDataSource_latestExisting
2020-02-18T14:50:09.2338511Z === CONT  TestAccGithubReleaseDataSource_latestExisting
2020-02-18T14:50:09.2339435Z --- PASS: TestAccGithubReleaseDataSource_latestExisting (0.51s)
2020-02-18T14:50:09.2339706Z PASS
2020-02-18T14:50:09.2340188Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.522s
2020-02-18T14:50:10.0681423Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:11.8679192Z === RUN   TestAccGithubReleaseDataSource_fetchByIdWithNoIdReturnsError
2020-02-18T14:50:11.8679739Z === PAUSE TestAccGithubReleaseDataSource_fetchByIdWithNoIdReturnsError
2020-02-18T14:50:11.8680029Z === CONT  TestAccGithubReleaseDataSource_fetchByIdWithNoIdReturnsError
2020-02-18T14:50:11.8680983Z --- PASS: TestAccGithubReleaseDataSource_fetchByIdWithNoIdReturnsError (0.02s)
2020-02-18T14:50:11.8681250Z PASS
2020-02-18T14:50:11.8681721Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.028s
2020-02-18T14:50:12.6950597Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:15.0657962Z === RUN   TestAccGithubReleaseDataSource_fetchByIdExisting
2020-02-18T14:50:15.0658554Z === PAUSE TestAccGithubReleaseDataSource_fetchByIdExisting
2020-02-18T14:50:15.0658842Z === CONT  TestAccGithubReleaseDataSource_fetchByIdExisting
2020-02-18T14:50:15.0659804Z --- PASS: TestAccGithubReleaseDataSource_fetchByIdExisting (0.53s)
2020-02-18T14:50:15.0660128Z PASS
2020-02-18T14:50:15.0660615Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.544s
2020-02-18T14:50:15.8810603Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:17.7187951Z === RUN   TestAccGithubReleaseDataSource_fetchByTagNoTagReturnsError
2020-02-18T14:50:17.7188151Z === PAUSE TestAccGithubReleaseDataSource_fetchByTagNoTagReturnsError
2020-02-18T14:50:17.7188281Z === CONT  TestAccGithubReleaseDataSource_fetchByTagNoTagReturnsError
2020-02-18T14:50:17.7189115Z --- PASS: TestAccGithubReleaseDataSource_fetchByTagNoTagReturnsError (0.02s)
2020-02-18T14:50:17.7189256Z PASS
2020-02-18T14:50:17.7189601Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.028s
2020-02-18T14:50:18.5142157Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:20.8030885Z === RUN   TestAccGithubReleaseDataSource_fetchByTagExisting
2020-02-18T14:50:20.8031113Z === PAUSE TestAccGithubReleaseDataSource_fetchByTagExisting
2020-02-18T14:50:20.8031268Z === CONT  TestAccGithubReleaseDataSource_fetchByTagExisting
2020-02-18T14:50:20.8032112Z --- PASS: TestAccGithubReleaseDataSource_fetchByTagExisting (0.43s)
2020-02-18T14:50:20.8032271Z PASS
2020-02-18T14:50:20.8032621Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.441s
2020-02-18T14:50:21.6270831Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]
2020-02-18T14:50:23.4746254Z === RUN   TestAccGithubReleaseDataSource_invalidRetrieveMethodReturnsError
2020-02-18T14:50:23.4746484Z === PAUSE TestAccGithubReleaseDataSource_invalidRetrieveMethodReturnsError
2020-02-18T14:50:23.4746636Z === CONT  TestAccGithubReleaseDataSource_invalidRetrieveMethodReturnsError
2020-02-18T14:50:23.4747720Z --- PASS: TestAccGithubReleaseDataSource_invalidRetrieveMethodReturnsError (0.02s)
2020-02-18T14:50:23.4747868Z PASS
2020-02-18T14:50:23.4748238Z ok  	github.com/terraform-providers/terraform-provider-github/github	0.029s
2020-02-18T14:50:24.3605821Z ?   	github.com/terraform-providers/terraform-provider-github	[no test files]

@jcudit jcudit self-assigned this Feb 18, 2020
@benj-fletch
Copy link
Contributor Author

Thanks for the review @jcudit! I have pushed up some changes that I think address your concerns and have replied inline to each comment. Can I request a re-review please?

@benj-fletch
Copy link
Contributor Author

Sorry! Realised the tests wouldn't work in that state so have pushed ^^. That's what I get for not running the tests before a push...

Copy link
Contributor

@jcudit jcudit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

My next steps are to run this through a final pass of our acceptance tests. If all is good, I think this is safe to merge.

@jcudit jcudit merged commit 7be5e1a into integrations:master Feb 20, 2020
@benj-fletch benj-fletch deleted the gh-144-releases-data-source branch February 20, 2020 08:03
@jcudit jcudit mentioned this pull request Feb 24, 2020
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
…releases-data-source

integrationsGH-144 - New Data Source: Github release
@benkeil
Copy link

benkeil commented Mar 22, 2023

How can I access the assets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants