Files
docker-machine/commands/url_test.go
Nathan LeClaire 5000139c8e Add ability to imply 'default' VM in commands
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
2016-01-15 17:10:08 -08:00

58 lines
1.3 KiB
Go

package commands
import (
"testing"
"github.com/docker/machine/commands/commandstest"
"github.com/docker/machine/drivers/fakedriver"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/libmachinetest"
"github.com/docker/machine/libmachine/state"
"github.com/stretchr/testify/assert"
)
func TestCmdURLMissingMachineName(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{}
api := &libmachinetest.FakeAPI{}
err := cmdURL(commandLine, api)
assert.Equal(t, ErrNoDefault, err)
}
func TestCmdURLTooManyNames(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
}
api := &libmachinetest.FakeAPI{}
err := cmdURL(commandLine, api)
assert.EqualError(t, err, "Error: Expected one machine name as an argument")
}
func TestCmdURL(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"machine"},
}
api := &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "machine",
Driver: &fakedriver.Driver{
MockState: state.Running,
MockIP: "120.0.0.1",
},
},
},
}
stdoutGetter := commandstest.NewStdoutGetter()
defer stdoutGetter.Stop()
err := cmdURL(commandLine, api)
assert.NoError(t, err)
assert.Equal(t, "tcp://120.0.0.1:2376\n", stdoutGetter.Output())
}