|
| 1 | +package commands |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/docker/machine/commands/commandstest" |
| 7 | + "github.com/docker/machine/drivers/fakedriver" |
| 8 | + "github.com/docker/machine/libmachine/host" |
| 9 | + "github.com/docker/machine/libmachine/libmachinetest" |
| 10 | + "github.com/docker/machine/libmachine/state" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestCmdURLMissingMachineName(t *testing.T) { |
| 15 | + commandLine := &commandstest.FakeCommandLine{} |
| 16 | + api := &libmachinetest.FakeAPI{} |
| 17 | + |
| 18 | + err := cmdURL(commandLine, api) |
| 19 | + |
| 20 | + assert.Equal(t, ErrNoDefault, err) |
| 21 | +} |
| 22 | + |
| 23 | +func TestCmdURLTooManyNames(t *testing.T) { |
| 24 | + commandLine := &commandstest.FakeCommandLine{ |
| 25 | + CliArgs: []string{"machineToRemove1", "machineToRemove2"}, |
| 26 | + } |
| 27 | + api := &libmachinetest.FakeAPI{} |
| 28 | + |
| 29 | + err := cmdURL(commandLine, api) |
| 30 | + |
| 31 | + assert.EqualError(t, err, "Error: Expected one machine name as an argument") |
| 32 | +} |
| 33 | + |
| 34 | +func TestCmdURL(t *testing.T) { |
| 35 | + commandLine := &commandstest.FakeCommandLine{ |
| 36 | + CliArgs: []string{"machine"}, |
| 37 | + } |
| 38 | + api := &libmachinetest.FakeAPI{ |
| 39 | + Hosts: []*host.Host{ |
| 40 | + { |
| 41 | + Name: "machine", |
| 42 | + Driver: &fakedriver.Driver{ |
| 43 | + MockState: state.Running, |
| 44 | + MockIP: "120.0.0.1", |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + stdoutGetter := commandstest.NewStdoutGetter() |
| 51 | + defer stdoutGetter.Stop() |
| 52 | + |
| 53 | + err := cmdURL(commandLine, api) |
| 54 | + |
| 55 | + assert.NoError(t, err) |
| 56 | + assert.Equal(t, "tcp://120.0.0.1:2376\n", stdoutGetter.Output()) |
| 57 | +} |
0 commit comments