diff --git a/command/apply_test.go b/command/apply_test.go index 72d52ddae..b50b9cd14 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -8,10 +8,12 @@ import ( "net/http" "net/url" "os" + "os/exec" "path/filepath" "reflect" "strings" "sync" + "syscall" "testing" "time" @@ -59,6 +61,36 @@ func TestApply(t *testing.T) { } } +// test apply with locked state +func TestApply_lockedState(t *testing.T) { + statePath := testTempFile(t) + + locker := exec.Command("go", "run", "testadata/statelocker.go", statePath) + locker.Stderr = os.Stderr + if err := locker.Start(); err != nil { + t.Fatal(err) + } + + defer locker.Process.Signal(syscall.SIGTERM) + + p := testProvider() + ui := new(cli.MockUi) + c := &ApplyCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + + args := []string{ + "-state", statePath, + testFixturePath("apply"), + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } +} + // high water mark counter type hwm struct { sync.Mutex