@@ -68,7 +68,7 @@ func TestStateMv(t *testing.T) {
6868 "test_instance.bar" ,
6969 }
7070 if code := c .Run (args ); code != 0 {
71- t .Fatalf ("bad : %d\n \n %s" , code , ui .ErrorWriter .String ())
71+ t .Fatalf ("return code : %d\n \n %s" , code , ui .ErrorWriter .String ())
7272 }
7373
7474 // Test it is correct
@@ -80,6 +80,70 @@ func TestStateMv(t *testing.T) {
8080 t .Fatalf ("bad: %#v" , backups )
8181 }
8282 testStateOutput (t , backups [0 ], testStateMvOutputOriginal )
83+
84+ // Change the single instance to a counted instance
85+ args = []string {
86+ "-state" , statePath ,
87+ "test_instance.bar" ,
88+ "test_instance.bar[0]" ,
89+ }
90+ if code := c .Run (args ); code != 0 {
91+ t .Fatalf ("return code: %d\n \n %s" , code , ui .ErrorWriter .String ())
92+ }
93+
94+ // extract the resource and verify the mode
95+ s := testStateRead (t , statePath )
96+ addr , diags := addrs .ParseAbsResourceStr ("test_instance.bar" )
97+ if diags .HasErrors () {
98+ t .Fatal (diags .Err ())
99+ }
100+ i := s .Resource (addr )
101+ if i .EachMode != states .EachList {
102+ t .Fatalf ("expected each mode List, got %s" , i .EachMode )
103+ }
104+
105+ // change from list to map
106+ args = []string {
107+ "-state" , statePath ,
108+ "test_instance.bar[0]" ,
109+ "test_instance.bar[\" baz\" ]" ,
110+ }
111+ if code := c .Run (args ); code != 0 {
112+ t .Fatalf ("return code: %d\n \n %s" , code , ui .ErrorWriter .String ())
113+ }
114+
115+ // extract the resource and verify the mode
116+ s = testStateRead (t , statePath )
117+ addr , diags = addrs .ParseAbsResourceStr ("test_instance.bar" )
118+ if diags .HasErrors () {
119+ t .Fatal (diags .Err ())
120+ }
121+ i = s .Resource (addr )
122+ if i .EachMode != states .EachMap {
123+ t .Fatalf ("expected each mode Map, got %s" , i .EachMode )
124+ }
125+
126+ // change from from map back to single
127+ args = []string {
128+ "-state" , statePath ,
129+ "test_instance.bar[\" baz\" ]" ,
130+ "test_instance.bar" ,
131+ }
132+ if code := c .Run (args ); code != 0 {
133+ t .Fatalf ("return code: %d\n \n %s" , code , ui .ErrorWriter .String ())
134+ }
135+
136+ // extract the resource and verify the mode
137+ s = testStateRead (t , statePath )
138+ addr , diags = addrs .ParseAbsResourceStr ("test_instance.bar" )
139+ if diags .HasErrors () {
140+ t .Fatal (diags .Err ())
141+ }
142+ i = s .Resource (addr )
143+ if i .EachMode != states .NoEach {
144+ t .Fatalf ("expected each mode NoEach, got %s" , i .EachMode )
145+ }
146+
83147}
84148
85149func TestStateMv_resourceToInstance (t * testing.T ) {
0 commit comments