Better testing of CLI

This commit is contained in:
Mitchell Hashimoto 2013-04-20 18:22:27 -06:00
parent a8853da063
commit 109be6b5e3
1 changed files with 7 additions and 1 deletions

View File

@ -8,11 +8,15 @@ import (
)
type TestCommand struct {
runArgs []string
runCalled bool
runEnv *Environment
}
func (tc *TestCommand) Run(env *Environment, args []string) int {
tc.runCalled = true
tc.runArgs = args
tc.runEnv = env
return 0
}
@ -40,8 +44,10 @@ func TestEnvironment_Cli_CallsRun(t *testing.T) {
config.Command["foo"] = command
env := NewEnvironment(config)
assert.Equal(env.Cli([]string{"foo"}), 0, "runs foo command")
assert.Equal(env.Cli([]string{"foo", "bar", "baz"}), 0, "runs foo command")
assert.True(command.runCalled, "run should've been called")
assert.Equal(command.runEnv, env, "should've ran with env")
assert.Equal(command.runArgs, []string{"bar", "baz"}, "should have right args")
}
func TestEnvironment_DefaultCli_Empty(t *testing.T) {