-
Notifications
You must be signed in to change notification settings - Fork 984
Expand file tree
/
Copy pathdata_source_github_actions_organization_permissions_test.go
More file actions
115 lines (105 loc) · 3.66 KB
/
data_source_github_actions_organization_permissions_test.go
File metadata and controls
115 lines (105 loc) · 3.66 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)
func TestAccGithubActionsOrganizationPermissionsDataSource(t *testing.T) {
t.Run("reads organization permissions without error", func(t *testing.T) {
config := `
resource "github_actions_organization_permissions" "test" {
allowed_actions = "local_only"
enabled_repositories = "all"
}
data "github_actions_organization_permissions" "test" {
depends_on = [github_actions_organization_permissions.test]
}
`
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("allowed_actions"),
knownvalue.StringExact("local_only"),
),
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("enabled_repositories"),
knownvalue.StringExact("all"),
),
},
},
},
})
})
t.Run("reads selected repository and action permissions", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repoName := fmt.Sprintf("%srepo-act-org-perm-ds-%s", testResourcePrefix, randomID)
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "%[1]s"
description = "Terraform acceptance tests %[1]s"
}
resource "github_actions_organization_permissions" "test" {
allowed_actions = "selected"
enabled_repositories = "selected"
allowed_actions_config {
github_owned_allowed = true
verified_allowed = true
patterns_allowed = ["actions/cache@*", "actions/checkout@*"]
}
enabled_repositories_config {
repository_ids = [github_repository.test.repo_id]
}
}
data "github_actions_organization_permissions" "test" {
depends_on = [github_actions_organization_permissions.test]
}
`, repoName)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("allowed_actions"),
knownvalue.StringExact("selected"),
),
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("enabled_repositories"),
knownvalue.StringExact("selected"),
),
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("allowed_actions_config").AtSliceIndex(0).AtMapKey("github_owned_allowed"),
knownvalue.Bool(true),
),
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("allowed_actions_config").AtSliceIndex(0).AtMapKey("verified_allowed"),
knownvalue.Bool(true),
),
statecheck.ExpectKnownValue(
"data.github_actions_organization_permissions.test",
tfjsonpath.New("enabled_repositories_config").AtSliceIndex(0).AtMapKey("repository_ids"),
knownvalue.SetSizeExact(1),
),
},
},
},
})
})
}