Revise SSH help flow and add 'docker-machine ssh' test

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire 2015-12-03 11:10:21 -08:00
parent 7f499308fc
commit ed8ed5f14e
2 changed files with 57 additions and 6 deletions

View File

@ -9,14 +9,13 @@ import (
func cmdSSH(c CommandLine, api libmachine.API) error {
// Check for help flag -- Needed due to SkipFlagParsing
for _, arg := range c.Args() {
if arg == "-help" || arg == "--help" || arg == "-h" {
c.ShowHelp()
return nil
}
firstArg := c.Args().First()
if firstArg == "-help" || firstArg == "--help" || firstArg == "-h" {
c.ShowHelp()
return nil
}
name := c.Args().First()
name := firstArg
if name == "" {
return ErrExpectedOneMachine
}

52
commands/ssh_test.go Normal file
View File

@ -0,0 +1,52 @@
package commands
import (
"testing"
"github.com/docker/machine/commands/commandstest"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/libmachinetest"
"github.com/stretchr/testify/assert"
)
func TestCmdSSH(t *testing.T) {
testCases := []struct {
commandLine CommandLine
api libmachine.API
expectedErr error
helpShown bool
}{
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{"-h"},
},
api: &libmachinetest.FakeAPI{},
expectedErr: nil,
helpShown: true,
},
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{"--help"},
},
api: &libmachinetest.FakeAPI{},
expectedErr: nil,
helpShown: true,
},
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{""},
},
api: &libmachinetest.FakeAPI{},
expectedErr: ErrExpectedOneMachine,
},
}
for _, tc := range testCases {
err := cmdSSH(tc.commandLine, tc.api)
assert.Equal(t, err, tc.expectedErr)
if fcl, ok := tc.commandLine.(*commandstest.FakeCommandLine); ok {
assert.Equal(t, tc.helpShown, fcl.HelpShown)
}
}
}