Skip to content

Commit a4887d9

Browse files
committed
Update e2e test - works as expected but is blocked at apply step by other work to allow PSS to be used with other commands.
1 parent d34f148 commit a4887d9

File tree

1 file changed

+28
-85
lines changed

1 file changed

+28
-85
lines changed

internal/command/e2etest/primary_test.go

Lines changed: 28 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -266,108 +266,51 @@ func TestPrimary_stateStore(t *testing.T) {
266266
}
267267

268268
//// INIT
269-
_, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache")
269+
stdout, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
270270
if err != nil {
271271
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
272272
}
273273

274-
//// PLAN
275-
_, stderr, err = tf.Run("plan", "-out=tfplan")
276-
if err != nil {
277-
t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
274+
if !strings.Contains(stdout, "Terraform created an empty state file for the default workspace") {
275+
t.Errorf("notice about creating the default workspace is missing from init output:\n%s", stdout)
278276
}
279277

278+
//// PLAN
279+
// No separate plan step; this test lets the apply make a plan.
280+
280281
//// APPLY
281-
stdout, stderr, err := tf.Run("apply", "tfplan")
282+
// TODO - allow apply to use state store. Otherwise this step fails as it's trying to migrate from PSS=>local backend
283+
stdout, stderr, err = tf.Run("apply", "-no-color")
282284
if err != nil {
283285
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
284286
}
285287

286-
if !strings.Contains(stdout, "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.") {
287-
t.Fatalf("wrong output:\nstdout:%s\nstderr%s", stdout, stderr)
288+
if !strings.Contains(stdout, "Resources: 1 added, 0 changed, 0 destroyed") {
289+
t.Errorf("incorrect apply tally; want 1 added:\n%s", stdout)
288290
}
289291

290-
/// DESTROY
292+
// INSPECT STATE
293+
stdout, stderr, err = tf.Run("state", "list")
294+
295+
//// DESTROY
291296
stdout, stderr, err = tf.Run("destroy", "-auto-approve")
292297
if err != nil {
293-
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
298+
t.Fatalf("unexpected destroy error: %s\nstderr:\n%s", err, stderr)
294299
}
295300

296-
if !strings.Contains(stdout, "Resources: 2 destroyed") {
297-
t.Fatalf("wrong destroy output\nstdout:%s\nstderr:%s", stdout, stderr)
298-
}
299-
300-
// //// INIT
301-
// stdout, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache")
302-
// if err != nil {
303-
// t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
304-
// }
305-
306-
// // Make sure we actually downloaded the plugins, rather than picking up
307-
// // copies that might be already installed globally on the system.
308-
// if !strings.Contains(stdout, "Installing hashicorp/template v") {
309-
// t.Errorf("template provider download message is missing from init output:\n%s", stdout)
310-
// t.Logf("(this can happen if you have a copy of the plugin in one of the global plugin search dirs)")
311-
// }
312-
// if !strings.Contains(stdout, "Installing hashicorp/null v") {
313-
// t.Errorf("null provider download message is missing from init output:\n%s", stdout)
314-
// t.Logf("(this can happen if you have a copy of the plugin in one of the global plugin search dirs)")
315-
// }
316-
317-
// //// PLAN
318-
// // No separate plan step; this test lets the apply make a plan.
319-
320-
// //// APPLY
321-
// stdout, stderr, err = tf.Run("apply")
322-
// if err != nil {
323-
// t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
324-
// }
325-
326-
// if !strings.Contains(stdout, "Resources: 1 added, 0 changed, 0 destroyed") {
327-
// t.Errorf("incorrect apply tally; want 1 added:\n%s", stdout)
328-
// }
329-
330-
// state, err := tf.LocalState()
331-
// if err != nil {
332-
// t.Fatalf("failed to read state file: %s", err)
333-
// }
334-
335-
// stateResources := state.RootModule().Resources
336-
// var gotResources []string
337-
// for n := range stateResources {
338-
// gotResources = append(gotResources, n)
339-
// }
340-
// sort.Strings(gotResources)
341-
342-
// wantResources := []string{
343-
// "data.template_file.test",
344-
// "null_resource.test",
345-
// }
346-
347-
// if !reflect.DeepEqual(gotResources, wantResources) {
348-
// t.Errorf("wrong resources in state\ngot: %#v\nwant: %#v", gotResources, wantResources)
349-
// }
350-
351-
// //// DESTROY
352-
// stdout, stderr, err = tf.Run("destroy", "-auto-approve")
353-
// if err != nil {
354-
// t.Fatalf("unexpected destroy error: %s\nstderr:\n%s", err, stderr)
355-
// }
356-
357-
// if !strings.Contains(stdout, "Resources: 1 destroyed") {
358-
// t.Errorf("incorrect destroy tally; want 1 destroyed:\n%s", stdout)
359-
// }
360-
361-
// state, err = tf.LocalState()
362-
// if err != nil {
363-
// t.Fatalf("failed to read state file after destroy: %s", err)
364-
// }
365-
366-
// stateResources = state.RootModule().Resources
367-
// if len(stateResources) != 0 {
368-
// t.Errorf("wrong resources in state after destroy; want none, but still have:%s", spew.Sdump(stateResources))
369-
// }
301+
if !strings.Contains(stdout, "Resources: 1 destroyed") {
302+
t.Errorf("incorrect destroy tally; want 1 destroyed:\n%s", stdout)
303+
}
370304

305+
state, err := tf.LocalState()
306+
if err != nil {
307+
t.Fatalf("failed to read state file after destroy: %s", err)
308+
}
309+
310+
stateResources := state.RootModule().Resources
311+
if len(stateResources) != 0 {
312+
t.Errorf("wrong resources in state after destroy; want none, but still have:%s", spew.Sdump(stateResources))
313+
}
371314
}
372315

373-
// TODO: TestPrimarySeparatePlan_stateStore
316+
// TODO: TestPrimarySeparatePlan_stateStore - once support for PSS in plan files is implemented

0 commit comments

Comments
 (0)