-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/hpc_cache_blob_target: fixing comments from code review
- Loading branch information
1 parent
43094a6
commit af8ca85
Showing
6 changed files
with
216 additions
and
105 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
azurerm/internal/services/storage/parsers/storage_container.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,39 @@ | ||
package parsers | ||
|
||
import "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
|
||
type StorageContainerResourceManagerId struct { | ||
Name string | ||
AccountName string | ||
BlobServiceName string | ||
ResourceGroup string | ||
} | ||
|
||
func StorageContainerResourceManagerID(input string) (*StorageContainerResourceManagerId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cache := StorageContainerResourceManagerId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if cache.Name, err = id.PopSegment("containers"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if cache.BlobServiceName, err = id.PopSegment("blobServices"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if cache.AccountName, err = id.PopSegment("storageAccounts"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cache, nil | ||
} |
88 changes: 88 additions & 0 deletions
88
azurerm/internal/services/storage/parsers/storage_container_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,88 @@ | ||
package parsers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestParseStorageContainerResourceManagerID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *StorageContainerResourceManagerId | ||
}{ | ||
{ | ||
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 Containers Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Storage Containers Resource Manager ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/containers/container1", | ||
Expected: &StorageContainerResourceManagerId{ | ||
ResourceGroup: "resGroup1", | ||
AccountName: "account1", | ||
BlobServiceName: "default", | ||
Name: "container1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Storage/storageAccounts/account1/blobServices/default/Containers/container1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Storage Container Data Plane ID", | ||
Input: "https://account1.blob.core.windows.net/container1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := StorageContainerResourceManagerID(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.BlobServiceName != v.Expected.BlobServiceName { | ||
t.Fatalf("Expected %q but got %q for Blob Service Name", v.Expected.BlobServiceName, actual.BlobServiceName) | ||
} | ||
|
||
if actual.AccountName != v.Expected.AccountName { | ||
t.Fatalf("Expected %q but got %q for Account Name", v.Expected.AccountName, actual.AccountName) | ||
} | ||
|
||
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
Oops, something went wrong.