|
| 1 | +package parse |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestCustomResourceProviderId(t *testing.T) { |
| 8 | + testData := []struct { |
| 9 | + Name string |
| 10 | + Input string |
| 11 | + Expected *CustomProviderId |
| 12 | + }{ |
| 13 | + { |
| 14 | + Name: "Empty", |
| 15 | + Input: "", |
| 16 | + Expected: nil, |
| 17 | + }, |
| 18 | + { |
| 19 | + Name: "No Resource Groups Segment", |
| 20 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", |
| 21 | + Expected: nil, |
| 22 | + }, |
| 23 | + { |
| 24 | + Name: "No Resource Groups Value", |
| 25 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", |
| 26 | + Expected: nil, |
| 27 | + }, |
| 28 | + { |
| 29 | + Name: "Resource Group ID", |
| 30 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", |
| 31 | + Expected: nil, |
| 32 | + }, |
| 33 | + { |
| 34 | + Name: "Missing Search Services Value", |
| 35 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/", |
| 36 | + Expected: nil, |
| 37 | + }, |
| 38 | + { |
| 39 | + Name: "Search Service ID", |
| 40 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/Provider1", |
| 41 | + Expected: &CustomProviderId{ |
| 42 | + Name: "Provider1", |
| 43 | + ResourceGroup: "resGroup1", |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + Name: "Wrong Casing", |
| 48 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/ResourceProviders/Service1", |
| 49 | + Expected: nil, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, v := range testData { |
| 54 | + t.Logf("[DEBUG] Testing %q", v.Name) |
| 55 | + |
| 56 | + actual, err := CustomProviderID(v.Input) |
| 57 | + if err != nil { |
| 58 | + if v.Expected == nil { |
| 59 | + continue |
| 60 | + } |
| 61 | + |
| 62 | + t.Fatalf("Expected a value but got an error: %s", err) |
| 63 | + } |
| 64 | + |
| 65 | + if actual.Name != v.Expected.Name { |
| 66 | + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) |
| 67 | + } |
| 68 | + |
| 69 | + if actual.ResourceGroup != v.Expected.ResourceGroup { |
| 70 | + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments