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
|
package paths
import (
"testing"
"github.com/Azure/go-autorest/autorest/azure"
)
func TestGetResourceID(t *testing.T) {
testData := []struct {
AccountName string
FileSystemName string
Path string
Expected string
}{
{
AccountName: "account1",
FileSystemName: "fs1",
Path: "test",
Expected: "https://account1.dfs.core.windows.net/fs1/test",
},
{
AccountName: "account1",
FileSystemName: "fs1",
Path: "test/test2",
Expected: "https://account1.dfs.core.windows.net/fs1/test/test2",
},
{
AccountName: "account1",
FileSystemName: "fs1",
Path: "",
Expected: "https://account1.dfs.core.windows.net/fs1/",
},
}
for _, v := range testData {
t.Logf("[DEBUG] Testing Path %q", v.Path)
c := NewWithEnvironment(azure.PublicCloud)
actual := c.GetResourceID(v.AccountName, v.FileSystemName, v.Path)
if actual != v.Expected {
t.Fatalf("Expected the Resource ID to be %q but got %q", v.Expected, actual)
}
}
}
func TestParseResourceID(t *testing.T) {
testData := []struct {
Input string
AccountName string
FileSystemName string
Path string
}{
{
Input: "https://account1.dfs.core.windows.net/fs1/test",
AccountName: "account1",
FileSystemName: "fs1",
Path: "test",
},
{
Input: "https://account1.dfs.core.windows.net/fs1/test/test2",
AccountName: "account1",
FileSystemName: "fs1",
Path: "test/test2",
},
{
Input: "https://account1.dfs.core.windows.net/fs1/",
AccountName: "account1",
FileSystemName: "fs1",
Path: "",
},
}
for _, v := range testData {
t.Logf("[DEBUG] Testing Path %q", v.Path)
actual, err := ParseResourceID(v.Input)
if err != nil {
t.Fatal(err)
}
if actual.AccountName != v.AccountName {
t.Fatalf("Expected the account name to be `%q` but got %q", v.AccountName, actual.AccountName)
}
if actual.FileSystemName != v.FileSystemName {
t.Fatalf("Expected the file system name to be `%q` but got %q", v.FileSystemName, actual.FileSystemName)
}
if actual.Path != v.Path {
t.Fatalf("Expected the path to be `%q` but got %q", v.Path, actual.Path)
}
}
}
|