func TestCmdRmforceDoesAutoConfirm(t *testing.T) { commandLine := &commandstest.FakeCommandLine{ CliArgs: []string{"machineToRemove1", "machineToRemove2"}, LocalFlags: &commandstest.FakeFlagger{ Data: map[string]interface{}{ "y": false, "force": true, }, }, } api := &libmachinetest.FakeAPI{ Hosts: []*host.Host{ { Name: "machineToRemove1", Driver: &fakedriver.Driver{}, }, { Name: "machineToRemove2", Driver: &fakedriver.Driver{}, }, }, } err := cmdRm(commandLine, api) assert.NoError(t, err) assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) assert.False(t, libmachinetest.Exists(api, "machineToRemove2")) }
func TestDontStopWhenADriverRemovalFails(t *testing.T) { commandLine := &commandstest.FakeCommandLine{ CliArgs: []string{"machineToRemove1", "machineToRemove2", "machineToRemove3"}, LocalFlags: &commandstest.FakeFlagger{ Data: map[string]interface{}{ "y": true, }, }, } api := &libmachinetest.FakeAPI{ Hosts: []*host.Host{ { Name: "machineToRemove1", Driver: &fakedriver.Driver{}, }, { Name: "machineToRemove2", Driver: &DriverWithRemoveWhichFail{}, }, { Name: "machineToRemove3", Driver: &fakedriver.Driver{}, }, }, } err := cmdRm(commandLine, api) assert.EqualError(t, err, "Error removing host \"machineToRemove2\": unknown error") assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) assert.True(t, libmachinetest.Exists(api, "machineToRemove2")) assert.False(t, libmachinetest.Exists(api, "machineToRemove3")) }
func TestDontRemoveMachineIsRemovalFailsAndNotForced(t *testing.T) { commandLine := &commandstest.FakeCommandLine{ CliArgs: []string{"machineToRemove1"}, LocalFlags: &commandstest.FakeFlagger{ Data: map[string]interface{}{ "y": true, "force": false, }, }, } api := &libmachinetest.FakeAPI{ Hosts: []*host.Host{ { Name: "machineToRemove1", Driver: &DriverWithRemoveWhichFail{}, }, }, } err := cmdRm(commandLine, api) assert.EqualError(t, err, "Error removing host \"machineToRemove1\": unknown error") assert.True(t, libmachinetest.Exists(api, "machineToRemove1")) }
func TestForceRemoveEvenWhenItFails(t *testing.T) { commandLine := &commandstest.FakeCommandLine{ CliArgs: []string{"machineToRemove1"}, LocalFlags: &commandstest.FakeFlagger{ Data: map[string]interface{}{ "y": true, "force": true, }, }, } api := &libmachinetest.FakeAPI{ Hosts: []*host.Host{ { Name: "machineToRemove1", Driver: &DriverWithRemoveWhichFail{}, }, }, } err := cmdRm(commandLine, api) assert.NoError(t, err) assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) }