-
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.
Merge pull request #3882 from terraform-providers/f/storage-state-mig…
…ration r/storage_share: switching the state migration over to 0.12 format
- Loading branch information
Showing
3 changed files
with
141 additions
and
102 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
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
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 |
---|---|---|
@@ -1,80 +1,93 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/Azure/go-autorest/autorest/azure" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAzureRMStorageShareMigrateState(t *testing.T) { | ||
cases := map[string]struct { | ||
StateVersion int | ||
ID string | ||
InputAttributes map[string]string | ||
ExpectedAttributes map[string]string | ||
Meta interface{} | ||
}{ | ||
"v0_1": { | ||
StateVersion: 0, | ||
ID: "some_id", | ||
InputAttributes: map[string]string{ | ||
"name": "some_id", | ||
"resource_group_name": "some_rgn", | ||
"storage_account_name": "some_sgn", | ||
}, | ||
ExpectedAttributes: map[string]string{ | ||
"id": "some_id/some_rgn/some_sgn", | ||
}, | ||
}, | ||
"v1_2_public": { | ||
StateVersion: 1, | ||
ID: "some_id", | ||
InputAttributes: map[string]string{ | ||
"name": "some_id", | ||
"resource_group_name": "some_rgn", | ||
"storage_account_name": "some_sgn", | ||
}, | ||
ExpectedAttributes: map[string]string{ | ||
"id": "https://some_sgn.file.core.windows.net/some_id", | ||
}, | ||
Meta: &ArmClient{ | ||
environment: azure.PublicCloud, | ||
}, | ||
}, | ||
"v1_2_germany": { | ||
StateVersion: 1, | ||
ID: "some_id", | ||
InputAttributes: map[string]string{ | ||
"name": "some_id", | ||
"resource_group_name": "some_rgn", | ||
"storage_account_name": "some_sgn", | ||
}, | ||
ExpectedAttributes: map[string]string{ | ||
"id": "https://some_sgn.file.core.cloudapi.de/some_id", | ||
}, | ||
Meta: &ArmClient{ | ||
environment: azure.GermanCloud, | ||
}, | ||
}, | ||
func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { | ||
clouds := []azure.Environment{ | ||
azure.ChinaCloud, | ||
azure.GermanCloud, | ||
azure.PublicCloud, | ||
azure.USGovernmentCloud, | ||
} | ||
|
||
for tn, tc := range cases { | ||
is := &terraform.InstanceState{ | ||
ID: tc.ID, | ||
Attributes: tc.InputAttributes, | ||
for _, cloud := range clouds { | ||
t.Logf("[DEBUG] Testing with Cloud %q", cloud.Name) | ||
|
||
input := map[string]interface{}{ | ||
"id": "share1", | ||
"name": "share1", | ||
"resource_group_name": "group1", | ||
"storage_account_name": "account1", | ||
"quota": 5120, | ||
} | ||
meta := &ArmClient{ | ||
environment: cloud, | ||
} | ||
expected := map[string]interface{}{ | ||
"id": "share1/group1/account1", | ||
"name": "share1", | ||
"resource_group_name": "group1", | ||
"storage_account_name": "account1", | ||
"quota": 5120, | ||
} | ||
is, err := resourceStorageShareMigrateState(tc.StateVersion, is, tc.Meta) | ||
|
||
actual, err := resourceStorageShareStateUpgradeV0ToV1(input, meta) | ||
if err != nil { | ||
t.Fatalf("bad: %s, err: %#v", tn, err) | ||
t.Fatalf("Expected no error but got: %s", err) | ||
} | ||
|
||
for k, v := range tc.ExpectedAttributes { | ||
actual := is.Attributes[k] | ||
if actual != v { | ||
t.Fatalf("Bad Storage Share Migrate for %q: %q\n\n expected: %q", k, actual, v) | ||
} | ||
if !reflect.DeepEqual(expected, actual) { | ||
t.Fatalf("Expected %+v. Got %+v. But expected them to be the same", expected, actual) | ||
} | ||
|
||
t.Logf("[DEBUG] Ok!") | ||
} | ||
} | ||
|
||
func TestAzureRMStorageShareMigrateStateV1ToV2(t *testing.T) { | ||
clouds := []azure.Environment{ | ||
azure.ChinaCloud, | ||
azure.GermanCloud, | ||
azure.PublicCloud, | ||
azure.USGovernmentCloud, | ||
} | ||
|
||
for _, cloud := range clouds { | ||
t.Logf("[DEBUG] Testing with Cloud %q", cloud.Name) | ||
|
||
input := map[string]interface{}{ | ||
"id": "share1/group1/account1", | ||
"name": "share1", | ||
"resource_group_name": "group1", | ||
"storage_account_name": "account1", | ||
"quota": 5120, | ||
} | ||
meta := &ArmClient{ | ||
environment: cloud, | ||
} | ||
expected := map[string]interface{}{ | ||
"id": fmt.Sprintf("https://account1.file.%s/share1", cloud.StorageEndpointSuffix), | ||
"name": "share1", | ||
"resource_group_name": "group1", | ||
"storage_account_name": "account1", | ||
"quota": 5120, | ||
} | ||
|
||
actual, err := resourceStorageShareStateUpgradeV1ToV2(input, meta) | ||
if err != nil { | ||
t.Fatalf("Expected no error but got: %s", err) | ||
} | ||
|
||
if !reflect.DeepEqual(expected, actual) { | ||
t.Fatalf("Expected %+v. Got %+v. But expected them to be the same", expected, actual) | ||
} | ||
|
||
t.Logf("[DEBUG] Ok!") | ||
} | ||
} |