-
Notifications
You must be signed in to change notification settings - Fork 954
Expand file tree
/
Copy pathdata_source_github_organization_repositories_test.go
More file actions
64 lines (58 loc) · 1.83 KB
/
data_source_github_organization_repositories_test.go
File metadata and controls
64 lines (58 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
func TestAccGithubOrganizationRepositoriesDataSource(t *testing.T) {
t.Run("manages repositories", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repo1Name := fmt.Sprintf("%srepo-%s-1", testResourcePrefix, randomID)
repo2Name := fmt.Sprintf("%srepo-%s-2", testResourcePrefix, randomID)
config := `
resource "github_repository" "test1" {
name = "%s"
visibility = "private"
}
resource "github_repository" "test2" {
name = "%s"
visibility = "public"
archived = %t
depends_on = [github_repository.test1]
}
`
configWithDS := config + `
data "github_organization_repositories" "all" {
ignore_archived_repositories = %t
depends_on = [github_repository.test2]
}
`
const resourceAll = "data.github_organization_repositories.all"
const resourceSkipArchived = "data.github_organization_repositories.skip_archived"
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(config, repo1Name, repo2Name, false),
},
{
Config: fmt.Sprintf(config, repo1Name, repo2Name, true),
},
{
Config: fmt.Sprintf(configWithDS, repo1Name, repo2Name, true, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceAll, "repositories.#"),
),
},
{
Config: fmt.Sprintf(configWithDS, repo1Name, repo2Name, true, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceSkipArchived, "repositories.#"),
),
},
},
})
})
}