Skip to content

Commit

Permalink
Add unit test for ApiManagementApiDiagnosticID
Browse files Browse the repository at this point in the history
Signed-off-by: Sune Keller <[email protected]>
  • Loading branch information
sirlatrom committed Sep 4, 2020
1 parent 1c93103 commit 936bc51
Showing 1 changed file with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package parse

import "testing"

func TestApiManagementApiDiagnosticID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *ApiManagementApiDiagnosticId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing Service Name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/",
Expected: nil,
},
{
Name: "Missing APIs",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1",
Expected: nil,
},
{
Name: "Missing APIs Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/apis",
Expected: nil,
},
{
Name: "Missing Diagnostics",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/apis/api1",
Expected: nil,
},
{
Name: "Missing Diagnostics Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/apis/api1/diagnostics",
Expected: nil,
},
{
Name: "Diagnostic ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/apis/api1/diagnostics/applicationinsights",
Expected: &ApiManagementApiDiagnosticId{
Name: "applicationinsights",
ApiName: "api1",
ServiceName: "service1",
ResourceGroup: "resGroup1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/APIs/api1/diagnostics/applicationinsights",
Expected: nil,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := ApiManagementApiDiagnosticID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}

if actual.ApiName != v.Expected.ApiName {
t.Fatalf("Expected %q but got %q for API Name", v.Expected.ApiName, actual.ApiName)
}

if actual.ServiceName != v.Expected.ServiceName {
t.Fatalf("Expected %q but got %q for Service Name", v.Expected.Name, actual.Name)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}

0 comments on commit 936bc51

Please sign in to comment.