From d6837e2f31704dd615184934fefe8cf5643dc566 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 19 Jan 2015 15:47:17 -1000 Subject: [PATCH] command/lock: Adding simple test --- command/lock_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 command/lock_test.go diff --git a/command/lock_test.go b/command/lock_test.go new file mode 100644 index 0000000000..df3f029867 --- /dev/null +++ b/command/lock_test.go @@ -0,0 +1,37 @@ +package command + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "testing" + + "github.com/mitchellh/cli" +) + +func TestLockCommand_implements(t *testing.T) { + var _ cli.Command = &LockCommand{} +} + +func TestLockCommandRun(t *testing.T) { + a1 := testAgent(t) + defer a1.Shutdown() + waitForLeader(t, a1.httpAddr) + + ui := new(cli.MockUi) + c := &LockCommand{Ui: ui} + filePath := filepath.Join(a1.dir, "test_touch") + touchCmd := fmt.Sprintf("touch '%s'", filePath) + args := []string{"-http-addr=" + a1.httpAddr, "test/prefix", touchCmd} + + code := c.Run(args) + if code != 0 { + t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) + } + + // Check for the file + _, err := ioutil.ReadFile(filePath) + if err != nil { + t.Fatalf("err: %v", err) + } +}