command/lock: Adding simple test

This commit is contained in:
Armon Dadgar 2015-01-19 15:47:17 -10:00
parent b52c14d1b2
commit c6dbb7e76c
1 changed files with 37 additions and 0 deletions

37
command/lock_test.go Normal file
View File

@ -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)
}
}