47 lines
879 B
Go
47 lines
879 B
Go
|
package command
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/terraform"
|
||
|
"github.com/mitchellh/cli"
|
||
|
)
|
||
|
|
||
|
// Since we can't unlock a local state file, just test that calling unlock
|
||
|
// doesn't fail.
|
||
|
// TODO: mock remote state for UI testing
|
||
|
func TestUnlock(t *testing.T) {
|
||
|
td := tempDir(t)
|
||
|
os.MkdirAll(td, 0755)
|
||
|
defer os.RemoveAll(td)
|
||
|
defer testChdir(t, td)()
|
||
|
|
||
|
// Write the legacy state
|
||
|
statePath := DefaultStateFilename
|
||
|
{
|
||
|
f, err := os.Create(statePath)
|
||
|
if err != nil {
|
||
|
t.Fatalf("err: %s", err)
|
||
|
}
|
||
|
err = terraform.WriteState(testState(), f)
|
||
|
f.Close()
|
||
|
if err != nil {
|
||
|
t.Fatalf("err: %s", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
p := testProvider()
|
||
|
ui := new(cli.MockUi)
|
||
|
c := &UnlockCommand{
|
||
|
Meta: Meta{
|
||
|
ContextOpts: testCtxConfig(p),
|
||
|
Ui: ui,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
if code := c.Run(nil); code != 0 {
|
||
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||
|
}
|
||
|
}
|