-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new resource: azurerm_hpc_cache_blob_target
- Loading branch information
Showing
9 changed files
with
779 additions
and
0 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
azurerm/internal/services/storage/parsers/hpc_cache_target.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,38 @@ | ||
package parsers | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type HPCCacheTargetId struct { | ||
ResourceGroup string | ||
Cache string | ||
Name string | ||
} | ||
|
||
func HPCCacheTargetID(input string) (*HPCCacheTargetId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse HPC Cache Target ID %q: %+v", input, err) | ||
} | ||
|
||
target := HPCCacheTargetId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if target.Cache, err = id.PopSegment("caches"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if target.Name, err = id.PopSegment("storageTargets"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &target, nil | ||
} |
89 changes: 89 additions & 0 deletions
89
azurerm/internal/services/storage/parsers/hpc_cache_target_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,89 @@ | ||
package parsers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestHPCCacheTargetID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Error bool | ||
Expect *HPCCacheTargetId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Cache Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "With Cache Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "Missing Storage Target Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/storageTargets", | ||
Error: true, | ||
}, | ||
{ | ||
Name: "With Storage Target Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/storageTargets/target1", | ||
Expect: &HPCCacheTargetId{ | ||
ResourceGroup: "resGroup1", | ||
Cache: "cache1", | ||
Name: "target1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/StorageTargets/target1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := HPCCacheTargetID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expect.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) | ||
} | ||
|
||
if actual.Cache != v.Expect.Cache { | ||
t.Fatalf("Expected %q but got %q for Cache", v.Expect.Cache, actual.Cache) | ||
} | ||
|
||
if actual.Name != v.Expect.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) | ||
} | ||
} | ||
} |
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.