@@ -62,3 +62,61 @@ func TestInstanceStateUpgradeV0(t *testing.T) {
62
62
})
63
63
}
64
64
}
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 \n expected:\n \n %#v\n \n got:\n \n %#v\n \n " , testCase .ExpectedState , got )
119
+ }
120
+ })
121
+ }
122
+ }
0 commit comments