Skip to content

Commit

Permalink
parser unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauschenbusch committed Jun 12, 2020
1 parent cebdc98 commit c7925ad
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 0 deletions.
53 changes: 53 additions & 0 deletions azurerm/internal/services/kusto/parse/kusto_cluster_test.go
@@ -0,0 +1,53 @@
package parse

import (
"testing"
)

func TestKustoClusterId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *KustoClusterId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing Cluster",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/",
Expected: nil,
},
{
Name: "Cluster ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1",
Expected: &KustoClusterId{
Name: "cluster1",
ResourceGroup: "group1",
},
},
}

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

actual, err := KustoClusterID(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.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
@@ -0,0 +1,73 @@
package parse

import (
"testing"
)

func TestKustoDatabasePrincipalId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *KustoDatabasePrincipalId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing FQN",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Databases/database1",
Expected: nil,
},
{
Name: "Missing Role",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1/FQN/aaduser=;",
Expected: nil,
},
{
Name: "Database Principal ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1/Role/Viewer/FQN/aaduser=00000000-0000-0000-0000-000000000000;00000000-0000-0000-0000-000000000000",
Expected: &KustoDatabasePrincipalId{
Name: "aaduser=00000000-0000-0000-0000-000000000000;00000000-0000-0000-0000-000000000000",
Role: "Viewer",
Database: "database1",
Cluster: "cluster1",
ResourceGroup: "group1",
},
},
}

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

actual, err := KustoDatabasePrincipalID(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.Role != v.Expected.Role {
t.Fatalf("Expected %q but got %q for Role", v.Expected.Role, actual.Role)
}

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

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

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
63 changes: 63 additions & 0 deletions azurerm/internal/services/kusto/parse/kusto_database_test.go
@@ -0,0 +1,63 @@
package parse

import (
"testing"
)

func TestKustoDatabaseId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *KustoDatabaseId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing Cluster",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Databases/database1",
Expected: nil,
},
{
Name: "Missing Database",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1",
Expected: nil,
},
{
Name: "Database ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1",
Expected: &KustoDatabaseId{
Name: "database1",
Cluster: "cluster1",
ResourceGroup: "group1",
},
},
}

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

actual, err := KustoDatabaseID(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.Cluster != v.Expected.Cluster {
t.Fatalf("Expected %q but got %q for Cluster", v.Expected.Cluster, actual.Cluster)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
@@ -0,0 +1,73 @@
package parse

import (
"testing"
)

func TestKustoEventHubDataConnectionId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *KustoEventHubDataConnectionId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing Cluster",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Databases/database1",
Expected: nil,
},
{
Name: "Missing Database",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1",
Expected: nil,
},
{
Name: "Missing Data Connection",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1",
Expected: nil,
},
{
Name: "Data Connection ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1/DataConnections/connection1",
Expected: &KustoEventHubDataConnectionId{
Name: "connection1",
Database: "database1",
Cluster: "cluster1",
ResourceGroup: "group1",
},
},
}

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

actual, err := KustoEventHubDataConnectionID(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.Database != v.Expected.Database {
t.Fatalf("Expected %q but got %q for Database", v.Expected.Database, actual.Database)
}

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

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 c7925ad

Please sign in to comment.