Skip to content

Commit 4c756c2

Browse files
committed
Add state migration test
1 parent 3079cd8 commit 4c756c2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

internal/service/rds/instance_migrate_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,61 @@ func TestInstanceStateUpgradeV0(t *testing.T) {
6262
})
6363
}
6464
}
65+
66+
func TestInstanceStateUpgradeV1(t *testing.T) {
67+
ctx := acctest.Context(t)
68+
t.Parallel()
69+
70+
testCases := []struct {
71+
Description string
72+
InputState map[string]interface{}
73+
ExpectedState map[string]interface{}
74+
}{
75+
{
76+
Description: "missing state",
77+
InputState: nil,
78+
ExpectedState: nil,
79+
},
80+
{
81+
Description: "change id to resource id",
82+
InputState: map[string]interface{}{
83+
"allocated_storage": 10,
84+
"engine": "mariadb",
85+
"id": "my-test-instance",
86+
"identifier": "my-test-instance",
87+
"instance_class": "db.t2.micro",
88+
"password": "avoid-plaintext-passwords",
89+
"resource_id": "db-cnuap2ilnbmok4eunzklfvwjca",
90+
"tags": map[string]interface{}{"key1": "value1"},
91+
"username": "tfacctest",
92+
},
93+
ExpectedState: map[string]interface{}{
94+
"allocated_storage": 10,
95+
"engine": "mariadb",
96+
"id": "db-cnuap2ilnbmok4eunzklfvwjca",
97+
"identifier": "my-test-instance",
98+
"instance_class": "db.t2.micro",
99+
"password": "avoid-plaintext-passwords",
100+
"resource_id": "db-cnuap2ilnbmok4eunzklfvwjca",
101+
"tags": map[string]interface{}{"key1": "value1"},
102+
"username": "tfacctest",
103+
},
104+
},
105+
}
106+
107+
for _, testCase := range testCases {
108+
testCase := testCase
109+
t.Run(testCase.Description, func(t *testing.T) {
110+
t.Parallel()
111+
112+
got, err := tfrds.InstanceStateUpgradeV1(ctx, testCase.InputState, nil)
113+
if err != nil {
114+
t.Fatalf("error migrating state: %s", err)
115+
}
116+
117+
if !reflect.DeepEqual(testCase.ExpectedState, got) {
118+
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", testCase.ExpectedState, got)
119+
}
120+
})
121+
}
122+
}

0 commit comments

Comments
 (0)