@@ -175,11 +175,60 @@ func TestRunMoveAfterFailure(t *testing.T) {
175
175
}
176
176
177
177
func TestRunMoveBeforeSuccess (t * testing.T ) {
178
+ testCases := []struct {
179
+ name string
180
+ before string
181
+ after string // special prefix: dummy
182
+ wantScript string
183
+ }{
184
+ {
185
+ name : "happy path simple" ,
186
+ before : "testdata/move-before/01-before" ,
187
+ after : "dummy-01-after" ,
188
+ wantScript : "testdata/move-before/01-want" ,
189
+ },
190
+ }
191
+
192
+ for _ , tc := range testCases {
193
+ t .Run (tc .name , func (t * testing.T ) {
194
+ args := []string {"terravalet" , "move-before" }
195
+
196
+ runMoveSuccess (t , args , tc .before , tc .after , tc .wantScript )
197
+ })
198
+ }
178
199
}
179
200
180
201
func TestRunMoveBeforeFailure (t * testing.T ) {
202
+ testCases := []struct {
203
+ name string
204
+ before string // special value: "non-existing"
205
+ wantErr string
206
+ }{
207
+ {
208
+ name : "non existing BEFORE plan" ,
209
+ before : "non-existing" ,
210
+ wantErr : "opening the terraform BEFORE plan file: open non-existing.tfplan: no such file or directory" ,
211
+ },
212
+ {
213
+ name : "BEFORE plan must not contain resources to destroy" ,
214
+ before : "testdata/move-before/02-before" ,
215
+ wantErr : "BEFORE plan contains resources to destroy: [aws_batch_compute_environment.foo_batch]" ,
216
+ },
217
+ }
218
+
219
+ for _ , tc := range testCases {
220
+ t .Run (tc .name , func (t * testing.T ) {
221
+ args := []string {"terravalet" , "move-before" ,
222
+ "--before=" + tc .before , "--after=testdata/move-before/dummy-after" ,
223
+ }
224
+
225
+ runMoveFailure (t , args , tc .before , "non-existing" , tc .wantErr )
226
+ })
227
+ }
181
228
}
182
229
230
+ // If after has special prefix "dummy", it will not attempt to copy the
231
+ // corresponding tfplan files, to accomodate for move-before.
183
232
func runMoveSuccess (t * testing.T , args []string , before , after , wantScript string ) {
184
233
wantUpPath := wantScript + "_up.sh"
185
234
wantUp , err := os .ReadFile (wantUpPath )
@@ -204,9 +253,11 @@ func runMoveSuccess(t *testing.T, args []string, before, after, wantScript strin
204
253
filepath .Join (tmpDir , path .Base (before )+ ".tfplan" )); err != nil {
205
254
t .Fatal (err )
206
255
}
207
- if err := copyfile (after + ".tfplan" ,
208
- filepath .Join (tmpDir , path .Base (after )+ ".tfplan" )); err != nil {
209
- t .Fatal (err )
256
+ if ! strings .HasPrefix (after , "dummy" ) {
257
+ if err := copyfile (after + ".tfplan" ,
258
+ filepath .Join (tmpDir , path .Base (after )+ ".tfplan" )); err != nil {
259
+ t .Fatal (err )
260
+ }
210
261
}
211
262
212
263
// Change directory to the tmpdir.
0 commit comments