github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/command/unlock_test.go (about) 1 package command 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/hashicorp/terraform/terraform" 8 "github.com/mitchellh/cli" 9 ) 10 11 // Since we can't unlock a local state file, just test that calling unlock 12 // doesn't fail. 13 // TODO: mock remote state for UI testing 14 func TestUnlock(t *testing.T) { 15 td := tempDir(t) 16 os.MkdirAll(td, 0755) 17 defer os.RemoveAll(td) 18 defer testChdir(t, td)() 19 20 // Write the legacy state 21 statePath := DefaultStateFilename 22 { 23 f, err := os.Create(statePath) 24 if err != nil { 25 t.Fatalf("err: %s", err) 26 } 27 err = terraform.WriteState(testState(), f) 28 f.Close() 29 if err != nil { 30 t.Fatalf("err: %s", err) 31 } 32 } 33 34 p := testProvider() 35 ui := new(cli.MockUi) 36 c := &UnlockCommand{ 37 Meta: Meta{ 38 ContextOpts: testCtxConfig(p), 39 Ui: ui, 40 }, 41 } 42 43 if code := c.Run([]string{"-force"}); code != 0 { 44 t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) 45 } 46 }