Skip to content

Commit

Permalink
Add state migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed May 10, 2023
1 parent 3079cd8 commit 4c756c2
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions internal/service/rds/instance_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,61 @@ func TestInstanceStateUpgradeV0(t *testing.T) {
})
}
}

func TestInstanceStateUpgradeV1(t *testing.T) {
ctx := acctest.Context(t)
t.Parallel()

testCases := []struct {
Description string
InputState map[string]interface{}
ExpectedState map[string]interface{}
}{
{
Description: "missing state",
InputState: nil,
ExpectedState: nil,
},
{
Description: "change id to resource id",
InputState: map[string]interface{}{
"allocated_storage": 10,
"engine": "mariadb",
"id": "my-test-instance",
"identifier": "my-test-instance",
"instance_class": "db.t2.micro",
"password": "avoid-plaintext-passwords",
"resource_id": "db-cnuap2ilnbmok4eunzklfvwjca",
"tags": map[string]interface{}{"key1": "value1"},
"username": "tfacctest",
},
ExpectedState: map[string]interface{}{
"allocated_storage": 10,
"engine": "mariadb",
"id": "db-cnuap2ilnbmok4eunzklfvwjca",
"identifier": "my-test-instance",
"instance_class": "db.t2.micro",
"password": "avoid-plaintext-passwords",
"resource_id": "db-cnuap2ilnbmok4eunzklfvwjca",
"tags": map[string]interface{}{"key1": "value1"},
"username": "tfacctest",
},
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
t.Parallel()

got, err := tfrds.InstanceStateUpgradeV1(ctx, testCase.InputState, nil)
if err != nil {
t.Fatalf("error migrating state: %s", err)
}

if !reflect.DeepEqual(testCase.ExpectedState, got) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", testCase.ExpectedState, got)
}
})
}
}

0 comments on commit 4c756c2

Please sign in to comment.