| 1 |
package paths |
| 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 |
AccountName string |
| 12 |
FileSystemName string |
| 13 |
Path string |
| 14 |
Expected string |
| 15 |
}{ |
| 16 |
{ |
| 17 |
AccountName: "account1", |
| 18 |
FileSystemName: "fs1", |
| 19 |
Path: "test", |
| 20 |
Expected: "https://account1.dfs.core.windows.net/fs1/test", |
| 21 |
}, |
| 22 |
{ |
| 23 |
AccountName: "account1", |
| 24 |
FileSystemName: "fs1", |
| 25 |
Path: "test/test2", |
| 26 |
Expected: "https://account1.dfs.core.windows.net/fs1/test/test2", |
| 27 |
}, |
| 28 |
{ |
| 29 |
AccountName: "account1", |
| 30 |
FileSystemName: "fs1", |
| 31 |
Path: "", |
| 32 |
Expected: "https://account1.dfs.core.windows.net/fs1/", |
| 33 |
}, |
| 34 |
} |
| 35 |
for _, v := range testData { |
| 36 |
t.Logf("[DEBUG] Testing Path %q", v.Path) |
| 37 |
c := NewWithEnvironment(azure.PublicCloud) |
| 38 |
actual := c.GetResourceID(v.AccountName, v.FileSystemName, v.Path) |
| 39 |
if actual != v.Expected { |
| 40 |
t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual) |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestParseResourceID(t *testing.T) { |
| 46 |
testData := []struct { |
| 47 |
Input string |
| 48 |
AccountName string |
| 49 |
FileSystemName string |
| 50 |
Path string |
| 51 |
}{ |
| 52 |
{ |
| 53 |
Input: "https://account1.dfs.core.windows.net/fs1/test", |
| 54 |
AccountName: "account1", |
| 55 |
FileSystemName: "fs1", |
| 56 |
Path: "test", |
| 57 |
}, |
| 58 |
{ |
| 59 |
Input: "https://account1.dfs.core.windows.net/fs1/test/test2", |
| 60 |
AccountName: "account1", |
| 61 |
FileSystemName: "fs1", |
| 62 |
Path: "test/test2", |
| 63 |
}, |
| 64 |
{ |
| 65 |
Input: "https://account1.dfs.core.windows.net/fs1/", |
| 66 |
AccountName: "account1", |
| 67 |
FileSystemName: "fs1", |
| 68 |
Path: "", |
| 69 |
}, |
| 70 |
} |
| 71 |
for _, v := range testData { |
| 72 |
t.Logf("[DEBUG] Testing Path %q", v.Path) |
| 73 |
actual, err := ParseResourceID(v.Input) |
| 74 |
if err != nil { |
| 75 |
t.Fatal(err) |
| 76 |
} |
| 77 |
|
| 78 |
if actual.AccountName != v.AccountName { |
| 79 |
t.Fatalf("Expected the account name to be `%q` but got %q", v.AccountName, actual.AccountName) |
| 80 |
} |
| 81 |
|
| 82 |
if actual.FileSystemName != v.FileSystemName { |
| 83 |
t.Fatalf("Expected the file system name to be `%q` but got %q", v.FileSystemName, actual.FileSystemName) |
| 84 |
} |
| 85 |
|
| 86 |
if actual.Path != v.Path { |
| 87 |
t.Fatalf("Expected the path to be `%q` but got %q", v.Path, actual.Path) |
| 88 |
} |
| 89 |
} |
| 90 |
} |