Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6958 from jrauschenbusch/fix-eventgrid-subscripti…
…on-id-parser fix: eventgrid id parsers
- Loading branch information
Showing
5 changed files
with
246 additions
and
9 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
azurerm/internal/services/eventgrid/parse/eventgrid_domain_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestEventGridDomainId(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *EventGridDomainId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Domain", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/topics/topic1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "EventGrid Domain ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/domains/domain1", | ||
Expected: &EventGridDomainId{ | ||
Name: "domain1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := EventGridDomainID(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) | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
azurerm/internal/services/eventgrid/parse/eventgrid_domain_topic_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestEventGridDomainTopicId(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *EventGridDomainTopicId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Domain", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/providers/Microsoft.EventGrid/topics/topic1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Domain Topic ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/domains/domain1/topics/topic1", | ||
Expected: &EventGridDomainTopicId{ | ||
Name: "topic1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := EventGridDomainTopicID(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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
azurerm/internal/services/eventgrid/parse/eventgrid_event_subscription_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestEventGridEventSubscriptionId(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *EventGridEventSubscriptionId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Subscription Scope", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: &EventGridEventSubscriptionId{ | ||
Name: "subscription1", | ||
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
}, | ||
}, | ||
{ | ||
Name: "Resource Group", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: &EventGridEventSubscriptionId{ | ||
Name: "subscription1", | ||
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Storage Account Scope", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storage1/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: &EventGridEventSubscriptionId{ | ||
Name: "subscription1", | ||
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/storage1", | ||
}, | ||
}, | ||
{ | ||
Name: "Event Grid Domain Scope", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/domains/domain1/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: &EventGridEventSubscriptionId{ | ||
Name: "subscription1", | ||
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/domains/domain1", | ||
}, | ||
}, | ||
{ | ||
Name: "Event Grid Topic Scope", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/topics/topic1/providers/Microsoft.EventGrid/eventSubscriptions/subscription1", | ||
Expected: &EventGridEventSubscriptionId{ | ||
Name: "subscription1", | ||
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/topics/topic1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := EventGridEventSubscriptionID(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.Scope != v.Expected.Scope { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.Scope, actual.Scope) | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
azurerm/internal/services/eventgrid/parse/eventgrid_topic_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestEventGridTopicId(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *EventGridTopicId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Topic", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/providers/Microsoft.EventGrid/domains/domain1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "EventGrid Topic ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.EventGrid/topics/topic1", | ||
Expected: &EventGridTopicId{ | ||
Name: "topic1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := EventGridTopicID(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) | ||
} | ||
} | ||
} |