-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathresource_id_test.go
162 lines (153 loc) · 5.97 KB
/
resource_id_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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package shares
import (
"testing"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/blob/accounts"
)
func TestGetResourceManagerResourceID(t *testing.T) {
actual := Client{}.GetResourceManagerResourceID("11112222-3333-4444-5555-666677778888", "group1", "account1", "share1")
expected := "/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/group1/providers/Microsoft.Storage/storageAccounts/account1/fileServices/default/shares/share1"
if actual != expected {
t.Fatalf("Expected the Resource Manager Resource ID to be %q but got %q", expected, actual)
}
}
func TestParseShareIDStandard(t *testing.T) {
input := "https://example1.file.core.windows.net/share1"
expected := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "core.windows.net",
},
ShareName: "share1",
}
actual, err := ParseShareID(input, "core.windows.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountId.AccountName != expected.AccountId.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountId.AccountName, actual.AccountId.AccountName)
}
if actual.AccountId.SubDomainType != expected.AccountId.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.AccountId.SubDomainType, actual.AccountId.SubDomainType)
}
if actual.AccountId.DomainSuffix != expected.AccountId.DomainSuffix {
t.Fatalf("expected DomainSuffix to be %q but got %q", expected.AccountId.DomainSuffix, actual.AccountId.DomainSuffix)
}
if actual.ShareName != expected.ShareName {
t.Fatalf("expected ShareName to be %q but got %q", expected.ShareName, actual.ShareName)
}
}
func TestParseShareIDInADNSZone(t *testing.T) {
input := "https://example1.zone1.file.storage.azure.net/share1"
expected := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "storage.azure.net",
ZoneName: pointer.To("zone1"),
},
ShareName: "share1",
}
actual, err := ParseShareID(input, "storage.azure.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountId.AccountName != expected.AccountId.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountId.AccountName, actual.AccountId.AccountName)
}
if actual.AccountId.SubDomainType != expected.AccountId.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.AccountId.SubDomainType, actual.AccountId.SubDomainType)
}
if actual.AccountId.DomainSuffix != expected.AccountId.DomainSuffix {
t.Fatalf("expected DomainSuffix to be %q but got %q", expected.AccountId.DomainSuffix, actual.AccountId.DomainSuffix)
}
if pointer.From(actual.AccountId.ZoneName) != pointer.From(expected.AccountId.ZoneName) {
t.Fatalf("expected ZoneName to be %q but got %q", pointer.From(expected.AccountId.ZoneName), pointer.From(actual.AccountId.ZoneName))
}
if actual.ShareName != expected.ShareName {
t.Fatalf("expected ShareName to be %q but got %q", expected.ShareName, actual.ShareName)
}
}
func TestParseShareIDInAnEdgeZone(t *testing.T) {
input := "https://example1.file.zone1.edgestorage.azure.net/share1"
expected := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "edgestorage.azure.net",
ZoneName: pointer.To("zone1"),
IsEdgeZone: true,
},
ShareName: "share1",
}
actual, err := ParseShareID(input, "edgestorage.azure.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountId.AccountName != expected.AccountId.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountId.AccountName, actual.AccountId.AccountName)
}
if actual.AccountId.SubDomainType != expected.AccountId.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.AccountId.SubDomainType, actual.AccountId.SubDomainType)
}
if actual.AccountId.DomainSuffix != expected.AccountId.DomainSuffix {
t.Fatalf("expected DomainSuffix to be %q but got %q", expected.AccountId.DomainSuffix, actual.AccountId.DomainSuffix)
}
if pointer.From(actual.AccountId.ZoneName) != pointer.From(expected.AccountId.ZoneName) {
t.Fatalf("expected ZoneName to be %q but got %q", pointer.From(expected.AccountId.ZoneName), pointer.From(actual.AccountId.ZoneName))
}
if !actual.AccountId.IsEdgeZone {
t.Fatalf("expected the Account to be in an Edge Zone but it wasn't")
}
if actual.ShareName != expected.ShareName {
t.Fatalf("expected ShareName to be %q but got %q", expected.ShareName, actual.ShareName)
}
}
func TestFormatContainerIDStandard(t *testing.T) {
actual := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "core.windows.net",
IsEdgeZone: false,
},
ShareName: "share1",
}.ID()
expected := "https://example1.file.core.windows.net/share1"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}
func TestFormatContainerIDInDNSZone(t *testing.T) {
actual := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
ZoneName: pointer.To("zone2"),
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "storage.azure.net",
IsEdgeZone: false,
},
ShareName: "share1",
}.ID()
expected := "https://example1.zone2.file.storage.azure.net/share1"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}
func TestFormatContainerIDInEdgeZone(t *testing.T) {
actual := ShareId{
AccountId: accounts.AccountId{
AccountName: "example1",
ZoneName: pointer.To("zone2"),
SubDomainType: accounts.FileSubDomainType,
DomainSuffix: "edgestorage.azure.net",
IsEdgeZone: true,
},
ShareName: "share1",
}.ID()
expected := "https://example1.file.zone2.edgestorage.azure.net/share1"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}