Debian Codegraph @

storage/2020-08-04/table/tables/resource_id_test.go

raw
1 package tables
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.table.core.chinacloudapi.cn/Tables('table1')",
17 },
18 {
19 Environment: azure.GermanCloud,
20 Expected: "https://account1.table.core.cloudapi.de/Tables('table1')",
21 },
22 {
23 Environment: azure.PublicCloud,
24 Expected: "https://account1.table.core.windows.net/Tables('table1')",
25 },
26 {
27 Environment: azure.USGovernmentCloud,
28 Expected: "https://account1.table.core.usgovcloudapi.net/Tables('table1')",
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", "table1")
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 TestParseResourceID(t *testing.T) {
42 testData := []struct {
43 Environment azure.Environment
44 Input string
45 }{
46 {
47 Environment: azure.ChinaCloud,
48 Input: "https://account1.table.core.chinacloudapi.cn/Tables('table1')",
49 },
50 {
51 Environment: azure.GermanCloud,
52 Input: "https://account1.table.core.cloudapi.de/Tables('table1')",
53 },
54 {
55 Environment: azure.PublicCloud,
56 Input: "https://account1.table.core.windows.net/Tables('table1')",
57 },
58 {
59 Environment: azure.USGovernmentCloud,
60 Input: "https://account1.table.core.usgovcloudapi.net/Tables('table1')",
61 },
62 }
63 for _, v := range testData {
64 t.Logf("[DEBUG] Testing Environment %q", v.Environment.Name)
65 actual, err := ParseResourceID(v.Input)
66 if err != nil {
67 t.Fatal(err)
68 }
69
70 if actual.AccountName != "account1" {
71 t.Fatalf("Expected Account Name to be `account1` but got %q", actual.AccountName)
72 }
73 if actual.TableName != "table1" {
74 t.Fatalf("Expected Table Name to be `table1` but got %q", actual.TableName)
75 }
76 }
77 }