Debian Codegraph @

storage/2018-11-09/blob/containers/resource_id_test.go

raw
1 package containers
2
3 import (
4 "testing"
5
6 "github.com/Azure/go-autorest/autorest/azure"
7 )
8
9 func TestGetResourceID(t *testing.T) {
10 testData := []struct {
11 Environment azure.Environment
12 Expected string
13 }{
14 {
15 Environment: azure.ChinaCloud,
16 Expected: "https://account1.blob.core.chinacloudapi.cn/container1",
17 },
18 {
19 Environment: azure.GermanCloud,
20 Expected: "https://account1.blob.core.cloudapi.de/container1",
21 },
22 {
23 Environment: azure.PublicCloud,
24 Expected: "https://account1.blob.core.windows.net/container1",
25 },
26 {
27 Environment: azure.USGovernmentCloud,
28 Expected: "https://account1.blob.core.usgovcloudapi.net/container1",
29 },
30 }
31 for _, v := range testData {
32 t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name)
33 c := NewWithEnvironment(v.Environment)
34 actual := c.GetResourceID("account1", "container1")
35 if actual != v.Expected {
36 t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual)
37 }
38 }
39 }
40
41 func TestGetResourceManagerResourceID(t *testing.T) {
42 testData := []struct {
43 Environment azure.Environment
44 Expected string
45 }{
46 {
47 Environment: azure.ChinaCloud,
48 Expected: "/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/group1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/container1",
49 },
50 {
51 Environment: azure.GermanCloud,
52 Expected: "/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/group1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/container1",
53 },
54 {
55 Environment: azure.PublicCloud,
56 Expected: "/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/group1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/container1",
57 },
58 {
59 Environment: azure.USGovernmentCloud,
60 Expected: "/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/group1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/container1",
61 },
62 }
63 for _, v := range testData {
64 t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name)
65 c := NewWithEnvironment(v.Environment)
66 actual := c.GetResourceManagerResourceID("11112222-3333-4444-5555-666677778888", "group1", "account1", "container1")
67 if actual != v.Expected {
68 t.Fatalf("Expected the Resource Manager Resource ID to be %q but got %q", v.Expected, actual)
69 }
70 }
71 }
72
73 func TestParseResourceID(t *testing.T) {
74 testData := []struct {
75 Environment azure.Environment
76 Input string
77 }{
78 {
79 Environment: azure.ChinaCloud,
80 Input: "https://account1.blob.core.chinacloudapi.cn/container1",
81 },
82 {
83 Environment: azure.GermanCloud,
84 Input: "https://account1.blob.core.cloudapi.de/container1",
85 },
86 {
87 Environment: azure.PublicCloud,
88 Input: "https://account1.blob.core.windows.net/container1",
89 },
90 {
91 Environment: azure.USGovernmentCloud,
92 Input: "https://account1.blob.core.usgovcloudapi.net/container1",
93 },
94 }
95 for _, v := range testData {
96 t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name)
97 actual, err := ParseResourceID(v.Input)
98 if err != nil {
99 t.Fatal(err)
100 }
101
102 if actual.AccountName != "account1" {
103 t.Fatalf("Expected the account name to be `account1` but got %q", actual.AccountName)
104 }
105
106 if actual.ContainerName != "container1" {
107 t.Fatalf("Expected the container name to be `container1` but got %q", actual.ContainerName)
108 }
109 }
110 }