-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/storage_share: switching the state migration over to 0.12 format #3882
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I believe you can remove extraneous elements like
ValidateFunc
,ForceNew
,Required
, etc. from these old schema definitions since the state upgraders only need the type information, but either which way though!