-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathresource_library_permissions_test.go
134 lines (122 loc) · 4.91 KB
/
resource_library_permissions_test.go
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//go:build (all || permissions || resource_library_permissions) && (!exclude_permissions || !exclude_resource_library_permissions)
// +build all permissions resource_library_permissions
// +build !exclude_permissions !exclude_resource_library_permissions
package acceptancetests
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/datahelper"
)
func TestAccLibraryPermissions_SetPermissions(t *testing.T) {
projectName := testutils.GenerateResourceName()
config := hclLibraryPermissions(projectName, map[string]string{
"View": "allow",
"Administer": "allow",
"Create": "allow",
"ViewSecrets": "notset",
"Use": "allow",
"Owner": "allow",
})
tfNode := "azuredevops_library_permissions.permissions"
resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckProjectDestroyed,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testutils.CheckProjectExists(projectName),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
resource.TestCheckResourceAttrSet(tfNode, "principal"),
resource.TestCheckNoResourceAttr(tfNode, "serviceendpoint_id"),
resource.TestCheckResourceAttr(tfNode, "permissions.%", "6"),
resource.TestCheckResourceAttr(tfNode, "permissions.View", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Administer", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Create", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.ViewSecrets", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.Use", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Owner", "allow"),
),
},
},
})
}
func TestAccLibraryPermissions_UpdatePermissions(t *testing.T) {
projectName := testutils.GenerateResourceName()
config1 := hclLibraryPermissions(projectName, map[string]string{
"View": "allow",
"Administer": "allow",
"Create": "allow",
"ViewSecrets": "notset",
"Use": "allow",
"Owner": "allow",
})
config2 := hclLibraryPermissions(projectName, map[string]string{
"View": "allow",
"Administer": "notset",
"Create": "notset",
"ViewSecrets": "notset",
"Use": "notset",
"Owner": "notset",
})
tfNode := "azuredevops_library_permissions.permissions"
resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckProjectDestroyed,
Steps: []resource.TestStep{
{
Config: config1,
Check: resource.ComposeTestCheckFunc(
testutils.CheckProjectExists(projectName),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
resource.TestCheckResourceAttrSet(tfNode, "principal"),
resource.TestCheckResourceAttr(tfNode, "permissions.%", "6"),
resource.TestCheckResourceAttr(tfNode, "permissions.View", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Administer", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Create", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.ViewSecrets", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.Use", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Owner", "allow"),
),
},
{
Config: config2,
Check: resource.ComposeTestCheckFunc(
testutils.CheckProjectExists(projectName),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
resource.TestCheckResourceAttrSet(tfNode, "principal"),
resource.TestCheckResourceAttr(tfNode, "permissions.%", "6"),
resource.TestCheckResourceAttr(tfNode, "permissions.View", "allow"),
resource.TestCheckResourceAttr(tfNode, "permissions.Administer", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.Create", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.ViewSecrets", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.Use", "notset"),
resource.TestCheckResourceAttr(tfNode, "permissions.Owner", "notset"),
),
},
},
})
}
func hclLibraryPermissions(projectName string, permissions map[string]string) string {
LibraryPermissions := datahelper.JoinMap(permissions, "=", "\n")
return fmt.Sprintf(`
%s
data "azuredevops_group" "tf-project-readers" {
project_id = azuredevops_project.project.id
name = "Readers"
}
resource "azuredevops_library_permissions" "permissions" {
project_id = azuredevops_project.project.id
principal = data.azuredevops_group.tf-project-readers.id
permissions = {
%s
}
}
`, testutils.HclProjectResource(projectName),
LibraryPermissions,
)
}