-
Notifications
You must be signed in to change notification settings - Fork 21
/
resource_id_test.go
133 lines (125 loc) · 4.18 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
package accounts
import (
"testing"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
)
func TestParseAccountIDStandard(t *testing.T) {
input := "https://example.blob.core.windows.net"
expected := AccountId{
AccountName: "example",
SubDomainType: BlobSubDomainType,
DomainSuffix: "core.windows.net",
}
actual, err := ParseAccountID(input, "core.windows.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountName != expected.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountName, actual.AccountName)
}
if actual.SubDomainType != expected.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.SubDomainType, actual.SubDomainType)
}
if actual.DomainSuffix != expected.DomainSuffix {
t.Fatalf("expected DomainSuffix to be %q but got %q", expected.DomainSuffix, actual.DomainSuffix)
}
}
func TestParseAccountIDInDNSZone(t *testing.T) {
input := "https://example.zone.blob.storage.azure.net"
expected := AccountId{
AccountName: "example",
ZoneName: pointer.To("zone"),
SubDomainType: BlobSubDomainType,
DomainSuffix: "storage.azure.net",
}
actual, err := ParseAccountID(input, "storage.azure.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountName != expected.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountName, actual.AccountName)
}
if actual.ZoneName == nil {
t.Fatalf("expected ZoneName to have a value but got nil")
}
if *actual.ZoneName != *expected.ZoneName {
t.Fatalf("expected ZoneName to be %q but got %q", *expected.ZoneName, *actual.ZoneName)
}
if actual.SubDomainType != expected.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.SubDomainType, actual.SubDomainType)
}
if actual.DomainSuffix != expected.DomainSuffix {
t.Fatalf("expected DomainSuffix to be %q but got %q", expected.DomainSuffix, actual.DomainSuffix)
}
if actual.IsEdgeZone {
t.Fatalf("expected IsEdgeZone to be false but got %t", actual.IsEdgeZone)
}
}
func TestParseAccountIDInEdgeZone(t *testing.T) {
input := "https://example.blob.danger.edgestorage.azure.net"
expected := AccountId{
AccountName: "example",
ZoneName: pointer.To("danger"),
IsEdgeZone: true,
SubDomainType: BlobSubDomainType,
DomainSuffix: "edgestorage.azure.net",
}
actual, err := ParseAccountID(input, "edgestorage.azure.net")
if err != nil {
t.Fatalf(err.Error())
}
if actual.AccountName != expected.AccountName {
t.Fatalf("expected AccountName to be %q but got %q", expected.AccountName, actual.AccountName)
}
if actual.ZoneName == nil {
t.Fatalf("expected ZoneName to have a value but got nil")
}
if *actual.ZoneName != *expected.ZoneName {
t.Fatalf("expected ZoneName to be %q but got %q", *expected.ZoneName, *actual.ZoneName)
}
if actual.SubDomainType != expected.SubDomainType {
t.Fatalf("expected SubDomainType to be %q but got %q", expected.SubDomainType, actual.SubDomainType)
}
if !actual.IsEdgeZone {
t.Fatalf("expected IsEdgeZone to be true but got %t", actual.IsEdgeZone)
}
}
func TestFormatAccountIDStandard(t *testing.T) {
actual := AccountId{
AccountName: "example1",
ZoneName: nil,
SubDomainType: FileSubDomainType,
DomainSuffix: "core.windows.net",
IsEdgeZone: false,
}.ID()
expected := "https://example1.file.core.windows.net"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}
func TestFormatAccountIDInDNSZone(t *testing.T) {
actual := AccountId{
AccountName: "example1",
ZoneName: pointer.To("zone1"),
SubDomainType: FileSubDomainType,
DomainSuffix: "storage.azure.net",
IsEdgeZone: false,
}.ID()
expected := "https://example1.zone1.file.storage.azure.net"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}
func TestFormatAccountIDInEdgeZone(t *testing.T) {
actual := AccountId{
AccountName: "example1",
ZoneName: pointer.To("zone1"),
SubDomainType: FileSubDomainType,
DomainSuffix: "edgestorage.azure.net",
IsEdgeZone: true,
}.ID()
expected := "https://example1.file.zone1.edgestorage.azure.net"
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}