|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
7 | 8 | ) |
8 | 9 |
|
9 | | -// TestAccGithubOrganizationAppInstallations requires at least one GitHub App |
10 | | -// to be installed in the test organization (GITHUB_OWNER). If no apps are |
11 | | -// installed, the attribute checks below will fail. |
12 | 10 | func TestAccGithubOrganizationAppInstallations(t *testing.T) { |
13 | | - config := `data "github_organization_app_installations" "test" {}` |
14 | | - |
15 | | - resource.Test(t, resource.TestCase{ |
16 | | - PreCheck: func() { skipUnlessHasOrgs(t) }, |
17 | | - ProviderFactories: providerFactories, |
18 | | - Steps: []resource.TestStep{ |
19 | | - { |
20 | | - Config: config, |
21 | | - Check: resource.ComposeAggregateTestCheckFunc( |
22 | | - resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.id"), |
23 | | - resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.app_slug"), |
24 | | - resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.app_id"), |
25 | | - ), |
| 11 | + |
| 12 | + t.Run("basic", func(t *testing.T) { |
| 13 | + config := `data "github_organization_app_installations" "test" {}` |
| 14 | + |
| 15 | + resource.Test(t, resource.TestCase{ |
| 16 | + PreCheck: func() { |
| 17 | + skipUnlessHasOrgs(t) |
| 18 | + skipUnlessHasAppInstallations(t) |
26 | 19 | }, |
27 | | - }, |
| 20 | + ProviderFactories: providerFactories, |
| 21 | + Steps: []resource.TestStep{ |
| 22 | + { |
| 23 | + Config: config, |
| 24 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 25 | + resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.id"), |
| 26 | + resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.app_slug"), |
| 27 | + resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.app_id"), |
| 28 | + ), |
| 29 | + }, |
| 30 | + }, |
| 31 | + }) |
28 | 32 | }) |
29 | 33 | } |
| 34 | + |
| 35 | +func skipUnlessHasAppInstallations(t *testing.T) { |
| 36 | + t.Helper() |
| 37 | + |
| 38 | + meta, err := getTestMeta() |
| 39 | + if err != nil { |
| 40 | + t.Fatalf("failed to get test meta: %s", err) |
| 41 | + } |
| 42 | + |
| 43 | + installations, _, err := meta.v3client.Organizations.ListInstallations(context.Background(), meta.name, nil) |
| 44 | + if err != nil { |
| 45 | + t.Fatalf("failed to list app installations: %s", err) |
| 46 | + } |
| 47 | + |
| 48 | + if len(installations.Installations) == 0 { |
| 49 | + t.Skip("Skipping because no GitHub App installations found in the test organization") |
| 50 | + } |
| 51 | +} |
0 commit comments