mirror of https://github.com/docker/docs.git
Revise SSH help flow and add 'docker-machine ssh' test
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
parent
7f499308fc
commit
ed8ed5f14e
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue