-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathmanagement_group_test.go
83 lines (77 loc) · 2.01 KB
/
management_group_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
package parse
import "testing"
func TestManagementGroupID(t *testing.T) {
testData := []struct {
Name string
Input string
Error bool
Expected *ManagementGroupId
}{
{
Name: "Empty",
Input: "",
Error: true,
},
{
Name: "No Management Groups Segment",
Input: "/providers/Microsoft.Management",
Error: true,
},
{
Name: "No Management Group ID",
Input: "/providers/Microsoft.Management/managementGroups/",
Error: true,
},
{
Name: "Management Group ID in UUID",
Input: "/providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000000",
Expected: &ManagementGroupId{
Name: "00000000-0000-0000-0000-000000000000",
},
},
{
Name: "Management Group ID in Readable ID",
Input: "/providers/Microsoft.Management/managementGroups/myGroup",
Expected: &ManagementGroupId{
Name: "myGroup",
},
},
{
Name: "Management Group ID in UUID with wrong casing",
Input: "/providers/microsoft.management/managementgroups/00000000-0000-0000-0000-000000000000",
Expected: &ManagementGroupId{
Name: "00000000-0000-0000-0000-000000000000",
},
},
{
Name: "Management Group ID in Readable ID with wrong casing",
Input: "/providers/microsoft.management/managementgroups/group1",
Expected: &ManagementGroupId{
Name: "group1",
},
},
{
Name: "Invalid Management group id",
Input: "/providers/Microsoft.Management/managementGroups/myGroup/another",
Error: true,
},
{
Name: "Resource ID in management group",
Input: "/providers/Microsoft.Management/managementGroups/myGroup/providers/Microsoft.Authorization/policyDefinitions/def1",
Error: true,
},
}
for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)
actual, err := ManagementGroupID(v.Input)
if err != nil {
if v.Error {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}
if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}