Skip to content

Commit 102ba5d

Browse files
committed
chore: github_release_asset data source tests use new test patterns
Per code review feedback from @deiga (#2514 (comment)), this updates the github_release_asset data source tests to use the new testing patterns implemented in #2986 This was tested via: ``` $ TF_ACC=1 \ go test -v ./... -run ^TestAccGithubReleaseAssetDataSource ? github.com/integrations/terraform-provider-github/v6 [no test files] === RUN TestAccGithubReleaseAssetDataSource === RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID --- PASS: TestAccGithubReleaseAssetDataSource (5.91s) --- PASS: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID (5.91s) PASS ok github.com/integrations/terraform-provider-github/v6/github 6.788s ``` Signed-off-by: Mike Ball <mikedball@gmail.com>
1 parent 424942d commit 102ba5d

File tree

2 files changed

+28
-40
lines changed

2 files changed

+28
-40
lines changed

github/data_source_github_release_asset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strconv"
77
"strings"
88

9-
"github.com/google/go-github/v67/github"
9+
"github.com/google/go-github/v81/github"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
)

github/data_source_github_release_asset_test.go

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ import (
1010

1111
func TestAccGithubReleaseAssetDataSource(t *testing.T) {
1212

13-
testReleaseRepository := "go-github-issue-demo-1"
14-
if os.Getenv("GITHUB_TEMPLATE_REPOSITORY") != "" {
15-
testReleaseRepository = os.Getenv("GITHUB_TEMPLATE_REPOSITORY")
16-
}
13+
testReleaseRepository := testAccConf.testPublicRepository
1714

18-
testReleaseAssetID := "151970555"
19-
if os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_ID") != "" {
20-
testReleaseAssetID = os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_ID")
15+
// NOTE: the default repository, owner, asset ID, asset name, and asset content
16+
// values can be overridden with GITHUB_TEST* environment variables to exercise
17+
// tests against different release assets in development.
18+
if os.Getenv("GITHUB_TEST_REPOSITORY") != "" {
19+
testReleaseRepository = os.Getenv("GITHUB_TEST_REPOSITORY")
2120
}
2221

23-
testReleaseAssetName := "foo.txt"
24-
if os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_NAME") != "" {
25-
testReleaseAssetName = os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_NAME")
22+
// The terraform-provider-github_6.4.0_manifest.json asset ID from
23+
// https://github.com/integrations/terraform-provider-github/releases/tag/v6.4.0
24+
testReleaseAssetID := "207956097"
25+
if os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_ID") != "" {
26+
testReleaseAssetID = os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_ID")
2627
}
2728

28-
testReleaseAssetContent := "Hello, world!\n"
29-
if os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_CONTENT") != "" {
30-
testReleaseAssetContent = os.Getenv("GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_CONTENT")
29+
testReleaseAssetName := "terraform-provider-github_6.4.0_manifest.json"
30+
if os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_NAME") != "" {
31+
testReleaseAssetName = os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_NAME")
3132
}
3233

33-
testReleaseOwner := testOrganizationFunc()
34+
testReleaseAssetContent := "{\n \"version\": 1,\n \"metadata\": {\n \"protocol_versions\": [\n \"5.0\"\n ]\n }\n}\n"
35+
if os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_CONTENT") != "" {
36+
testReleaseAssetContent = os.Getenv("GITHUB_TEST_REPOSITORY_RELEASE_ASSET_CONTENT")
37+
}
3438

3539
t.Run("queries specified asset ID", func(t *testing.T) {
3640

@@ -40,7 +44,7 @@ func TestAccGithubReleaseAssetDataSource(t *testing.T) {
4044
owner = "%s"
4145
asset_id = "%s"
4246
}
43-
`, testReleaseRepository, testReleaseOwner, testReleaseAssetID)
47+
`, testReleaseRepository, testAccConf.testPublicRepositoryOwner, testReleaseAssetID)
4448

4549
check := resource.ComposeTestCheckFunc(
4650
resource.TestCheckResourceAttr(
@@ -54,31 +58,15 @@ func TestAccGithubReleaseAssetDataSource(t *testing.T) {
5458
),
5559
)
5660

57-
testCase := func(t *testing.T, mode string) {
58-
resource.Test(t, resource.TestCase{
59-
PreCheck: func() { skipUnlessMode(t, mode) },
60-
Providers: testAccProviders,
61-
Steps: []resource.TestStep{
62-
{
63-
Config: config,
64-
Check: check,
65-
},
61+
resource.Test(t, resource.TestCase{
62+
ProviderFactories: providerFactories,
63+
Providers: testAccProviders,
64+
Steps: []resource.TestStep{
65+
{
66+
Config: config,
67+
Check: check,
6668
},
67-
})
68-
}
69-
70-
t.Run("with an anonymous account", func(t *testing.T) {
71-
testCase(t, anonymous)
72-
})
73-
74-
t.Run("with an individual account", func(t *testing.T) {
75-
testCase(t, individual)
69+
},
7670
})
77-
78-
t.Run("with an organization account", func(t *testing.T) {
79-
testCase(t, organization)
80-
})
81-
8271
})
83-
8472
}

0 commit comments

Comments
 (0)