Browse Source

command/exec: High level tests

pull/312/head
Armon Dadgar 10 years ago
parent
commit
de4adc4f66
  1. 6
      command/exec.go
  2. 48
      command/exec_test.go

6
command/exec.go

@ -18,6 +18,10 @@ import (
)
const (
// rExecPrefix is the prefix in the KV store used to
// store the remote exec data
rExecPrefix = "_rexec"
// rExecFileName is the name of the file we append to
// the path, e.g. _rexec/session_id/job
rExecFileName = "job"
@ -108,7 +112,7 @@ func (c *ExecCommand) Run(args []string) int {
cmdFlags.StringVar(&c.conf.node, "node", "", "")
cmdFlags.StringVar(&c.conf.service, "service", "", "")
cmdFlags.StringVar(&c.conf.tag, "tag", "", "")
cmdFlags.StringVar(&c.conf.prefix, "prefix", "_rexec", "")
cmdFlags.StringVar(&c.conf.prefix, "prefix", rExecPrefix, "")
cmdFlags.DurationVar(&c.conf.replWait, "wait-repl", 100*time.Millisecond, "")
cmdFlags.DurationVar(&c.conf.wait, "wait", time.Second, "")
cmdFlags.BoolVar(&c.conf.verbose, "v", false, "")

48
command/exec_test.go

@ -0,0 +1,48 @@
package command
import (
"github.com/mitchellh/cli"
"strings"
"testing"
"github.com/hashicorp/consul/testutil"
)
func TestExecCommand_implements(t *testing.T) {
var _ cli.Command = &ExecCommand{}
}
func TestExecCommandRun(t *testing.T) {
a1 := testAgent(t)
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)
ui := new(cli.MockUi)
c := &ExecCommand{Ui: ui}
args := []string{"-http-addr=" + a1.httpAddr, "-wait=400ms", "uptime"}
code := c.Run(args)
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
if !strings.Contains(ui.OutputWriter.String(), "load") {
t.Fatalf("bad: %#v", ui.OutputWriter.String())
}
}
func waitForLeader(t *testing.T, httpAddr string) {
client, err := HTTPClient(httpAddr)
if err != nil {
t.Fatalf("err: %v", err)
}
testutil.WaitForResult(func() (bool, error) {
_, qm, err := client.Catalog().Nodes(nil)
if err != nil {
return false, err
}
return qm.KnownLeader, nil
}, func(err error) {
t.Fatalf("failed to find leader: %v", err)
})
}
Loading…
Cancel
Save