|
| 1 | +package parse |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestServiceBusNamespaceNetworkRuleID(t *testing.T) { |
| 6 | + testData := []struct { |
| 7 | + Name string |
| 8 | + Input string |
| 9 | + Error bool |
| 10 | + Expected *ServiceBusNamespaceNetworkRuleSetId |
| 11 | + }{ |
| 12 | + { |
| 13 | + Name: "Empty", |
| 14 | + Input: "", |
| 15 | + Error: true, |
| 16 | + }, |
| 17 | + { |
| 18 | + Name: "No Resource Groups Segment", |
| 19 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", |
| 20 | + Error: true, |
| 21 | + }, |
| 22 | + { |
| 23 | + Name: "No Resource Groups Value", |
| 24 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", |
| 25 | + Error: true, |
| 26 | + }, |
| 27 | + { |
| 28 | + Name: "Resource Group ID", |
| 29 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", |
| 30 | + Error: true, |
| 31 | + }, |
| 32 | + { |
| 33 | + Name: "Missing Service Bus Namespace Name", |
| 34 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/", |
| 35 | + Error: true, |
| 36 | + }, |
| 37 | + { |
| 38 | + Name: "Service Bus Namespace ID", |
| 39 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1", |
| 40 | + Error: true, |
| 41 | + }, |
| 42 | + { |
| 43 | + Name: "Missing Network Rule Name", |
| 44 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1/networkrulesets/", |
| 45 | + Error: true, |
| 46 | + }, |
| 47 | + { |
| 48 | + Name: "Service Bus Namespace Network Rule ID", |
| 49 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/namespaces/namespace1/networkrulesets/default", |
| 50 | + Expected: &ServiceBusNamespaceNetworkRuleSetId{ |
| 51 | + Name: "default", |
| 52 | + NamespaceName: "namespace1", |
| 53 | + ResourceGroup: "resGroup1", |
| 54 | + }, |
| 55 | + }, |
| 56 | + { |
| 57 | + Name: "Wrong casing", |
| 58 | + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ServiceBus/Namespaces/namespace1", |
| 59 | + Error: true, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + for _, v := range testData { |
| 64 | + t.Logf("[DEBUG] Testing %q", v.Name) |
| 65 | + |
| 66 | + actual, err := ServiceBusNamespaceNetworkRuleSetID(v.Input) |
| 67 | + if err != nil { |
| 68 | + if v.Error { |
| 69 | + continue |
| 70 | + } |
| 71 | + |
| 72 | + t.Fatalf("Expected a value but got an error: %s", err) |
| 73 | + } |
| 74 | + |
| 75 | + if actual.Name != v.Expected.Name { |
| 76 | + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) |
| 77 | + } |
| 78 | + |
| 79 | + if actual.NamespaceName != v.Expected.NamespaceName { |
| 80 | + t.Fatalf("Expected %q but got %q for Name", v.Expected.NamespaceName, actual.NamespaceName) |
| 81 | + } |
| 82 | + |
| 83 | + if actual.ResourceGroup != v.Expected.ResourceGroup { |
| 84 | + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments