From 9fa436e0bd30fdecdd7d051dce1bd8c0c0b5c1ea Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 3 Feb 2017 16:02:22 -0500 Subject: [PATCH] Add test for locked state in plan --- command/plan_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/command/plan_test.go b/command/plan_test.go index 3f0e2cf265..b9e25bf22e 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -39,6 +39,44 @@ func TestPlan(t *testing.T) { } } +func TestPlan_lockedState(t *testing.T) { + cwd, err := os.Getwd() + if err != nil { + t.Fatalf("err: %s", err) + } + + testPath := testFixturePath("plan") + unlock, err := testLockState(filepath.Join(testPath, DefaultStateFilename)) + if err != nil { + t.Fatal(err) + } + defer unlock() + + if err := os.Chdir(testPath); err != nil { + t.Fatalf("err: %s", err) + } + defer os.Chdir(cwd) + + p := testProvider() + ui := new(cli.MockUi) + c := &PlanCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + + args := []string{} + if code := c.Run(args); code == 0 { + t.Fatal("expected error") + } + + output := ui.ErrorWriter.String() + if !strings.Contains(output, "locked") { + t.Fatal("command output does not look like a lock error:", output) + } +} + func TestPlan_plan(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd)