mirror of https://github.com/docker/docs.git
Remove duplicated FakeApi
Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
parent
f00b0b83cf
commit
643b7349f7
|
@ -1,80 +0,0 @@
|
||||||
package commandstest
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/docker/machine/libmachine"
|
|
||||||
"github.com/docker/machine/libmachine/drivers"
|
|
||||||
"github.com/docker/machine/libmachine/host"
|
|
||||||
"github.com/docker/machine/libmachine/mcnerror"
|
|
||||||
"github.com/docker/machine/libmachine/state"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FakeLibmachineAPI struct {
|
|
||||||
Hosts []*host.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) NewHost(driver drivers.Driver) (*host.Host, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) Create(h *host.Host) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) Exists(name string) (bool, error) {
|
|
||||||
for _, host := range api.Hosts {
|
|
||||||
if name == host.Name {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) List() ([]string, error) {
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) Load(name string) (*host.Host, error) {
|
|
||||||
for _, host := range api.Hosts {
|
|
||||||
if name == host.Name {
|
|
||||||
return host, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, mcnerror.ErrHostDoesNotExist{
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) Remove(name string) error {
|
|
||||||
newHosts := []*host.Host{}
|
|
||||||
|
|
||||||
for _, host := range api.Hosts {
|
|
||||||
if name != host.Name {
|
|
||||||
newHosts = append(newHosts, host)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
api.Hosts = newHosts
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *FakeLibmachineAPI) Save(host *host.Host) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func State(api libmachine.API, name string) state.State {
|
|
||||||
host, _ := api.Load(name)
|
|
||||||
machineState, _ := host.Driver.GetState()
|
|
||||||
return machineState
|
|
||||||
}
|
|
||||||
|
|
||||||
func Exists(api libmachine.API, name string) bool {
|
|
||||||
exists, _ := api.Exists(name)
|
|
||||||
return exists
|
|
||||||
}
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
"github.com/docker/machine/libmachine/libmachinetest"
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/docker/machine/libmachine/persist/persisttest"
|
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -118,14 +117,12 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -156,14 +153,12 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -194,14 +189,12 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -232,14 +225,12 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -270,7 +261,6 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
|
@ -281,7 +271,6 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -316,7 +305,6 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{
|
||||||
FakeStore: &persisttest.FakeStore{
|
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "quux",
|
Name: "quux",
|
||||||
|
@ -327,7 +315,6 @@ func TestShellCfgSet(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -431,9 +418,7 @@ func TestShellCfgUnset(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{},
|
||||||
FakeStore: &persisttest.FakeStore{},
|
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
@ -485,9 +470,7 @@ func TestShellCfgUnset(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: &libmachinetest.FakeAPI{
|
api: &libmachinetest.FakeAPI{},
|
||||||
FakeStore: &persisttest.FakeStore{},
|
|
||||||
},
|
|
||||||
connChecker: &FakeConnChecker{
|
connChecker: &FakeConnChecker{
|
||||||
DockerHost: "tcp://1.2.3.4:2376",
|
DockerHost: "tcp://1.2.3.4:2376",
|
||||||
AuthOptions: nil,
|
AuthOptions: nil,
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdIPMissingMachineName(t *testing.T) {
|
func TestCmdIPMissingMachineName(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{}
|
commandLine := &commandstest.FakeCommandLine{}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdURL(commandLine, api)
|
err := cmdURL(commandLine, api)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestCmdIP(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machine"},
|
CliArgs: []string{"machine"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{
|
api := &libmachinetest.FakeAPI{
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "machine",
|
Name: "machine",
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdKillMissingMachineName(t *testing.T) {
|
func TestCmdKillMissingMachineName(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{}
|
commandLine := &commandstest.FakeCommandLine{}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdKill(commandLine, api)
|
err := cmdKill(commandLine, api)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestCmdKill(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machineToKill1", "machineToKill2"},
|
CliArgs: []string{"machineToKill1", "machineToKill2"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{
|
api := &libmachinetest.FakeAPI{
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "machineToKill1",
|
Name: "machineToKill1",
|
||||||
|
@ -49,7 +50,7 @@ func TestCmdKill(t *testing.T) {
|
||||||
err := cmdKill(commandLine, api)
|
err := cmdKill(commandLine, api)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToKill1"))
|
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill1"))
|
||||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToKill2"))
|
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill2"))
|
||||||
assert.Equal(t, state.Running, commandstest.State(api, "machine"))
|
assert.Equal(t, state.Running, libmachinetest.State(api, "machine"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,13 @@ import (
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdRmMissingMachineName(t *testing.T) {
|
func TestCmdRmMissingMachineName(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{}
|
commandLine := &commandstest.FakeCommandLine{}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdRm(commandLine, api)
|
err := cmdRm(commandLine, api)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestCmdRm(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{
|
api := &libmachinetest.FakeAPI{
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "machineToRemove1",
|
Name: "machineToRemove1",
|
||||||
|
@ -43,7 +44,7 @@ func TestCmdRm(t *testing.T) {
|
||||||
err := cmdRm(commandLine, api)
|
err := cmdRm(commandLine, api)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.False(t, commandstest.Exists(api, "machineToRemove1"))
|
assert.False(t, libmachinetest.Exists(api, "machineToRemove1"))
|
||||||
assert.False(t, commandstest.Exists(api, "machineToRemove2"))
|
assert.False(t, libmachinetest.Exists(api, "machineToRemove2"))
|
||||||
assert.True(t, commandstest.Exists(api, "machine"))
|
assert.True(t, libmachinetest.Exists(api, "machine"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdStopMissingMachineName(t *testing.T) {
|
func TestCmdStopMissingMachineName(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{}
|
commandLine := &commandstest.FakeCommandLine{}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdStop(commandLine, api)
|
err := cmdStop(commandLine, api)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestCmdStop(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machineToStop1", "machineToStop2"},
|
CliArgs: []string{"machineToStop1", "machineToStop2"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{
|
api := &libmachinetest.FakeAPI{
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "machineToStop1",
|
Name: "machineToStop1",
|
||||||
|
@ -49,7 +50,7 @@ func TestCmdStop(t *testing.T) {
|
||||||
err := cmdStop(commandLine, api)
|
err := cmdStop(commandLine, api)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToStop1"))
|
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToStop1"))
|
||||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToStop2"))
|
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToStop2"))
|
||||||
assert.Equal(t, state.Running, commandstest.State(api, "machine"))
|
assert.Equal(t, state.Running, libmachinetest.State(api, "machine"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
|
"github.com/docker/machine/libmachine/libmachinetest"
|
||||||
"github.com/docker/machine/libmachine/state"
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdURLMissingMachineName(t *testing.T) {
|
func TestCmdURLMissingMachineName(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{}
|
commandLine := &commandstest.FakeCommandLine{}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdURL(commandLine, api)
|
err := cmdURL(commandLine, api)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestCmdURLTooManyNames(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{}
|
api := &libmachinetest.FakeAPI{}
|
||||||
|
|
||||||
err := cmdURL(commandLine, api)
|
err := cmdURL(commandLine, api)
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ func TestCmdURL(t *testing.T) {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
CliArgs: []string{"machine"},
|
CliArgs: []string{"machine"},
|
||||||
}
|
}
|
||||||
api := &commandstest.FakeLibmachineAPI{
|
api := &libmachinetest.FakeAPI{
|
||||||
Hosts: []*host.Host{
|
Hosts: []*host.Host{
|
||||||
{
|
{
|
||||||
Name: "machine",
|
Name: "machine",
|
||||||
|
|
|
@ -1,26 +1,80 @@
|
||||||
package libmachinetest
|
package libmachinetest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/machine/libmachine"
|
||||||
"github.com/docker/machine/libmachine/drivers"
|
"github.com/docker/machine/libmachine/drivers"
|
||||||
"github.com/docker/machine/libmachine/host"
|
"github.com/docker/machine/libmachine/host"
|
||||||
"github.com/docker/machine/libmachine/persist/persisttest"
|
"github.com/docker/machine/libmachine/mcnerror"
|
||||||
|
"github.com/docker/machine/libmachine/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeAPI struct {
|
type FakeAPI struct {
|
||||||
*persisttest.FakeStore
|
Hosts []*host.Host
|
||||||
FakeNewDriver drivers.Driver
|
|
||||||
FakeNewHost *host.Host
|
|
||||||
NewPluginDriverErr, NewHostErr, CreateErr error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fapi *FakeAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) {
|
func (api *FakeAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) {
|
||||||
return fapi.FakeNewDriver, fapi.NewPluginDriverErr
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fapi *FakeAPI) NewHost(drivers.Driver) (*host.Host, error) {
|
func (api *FakeAPI) NewHost(driver drivers.Driver) (*host.Host, error) {
|
||||||
return fapi.FakeNewHost, fapi.NewHostErr
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fapi *FakeAPI) Create(h *host.Host) error {
|
func (api *FakeAPI) Create(h *host.Host) error {
|
||||||
return fapi.CreateErr
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakeAPI) Exists(name string) (bool, error) {
|
||||||
|
for _, host := range api.Hosts {
|
||||||
|
if name == host.Name {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakeAPI) List() ([]string, error) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakeAPI) Load(name string) (*host.Host, error) {
|
||||||
|
for _, host := range api.Hosts {
|
||||||
|
if name == host.Name {
|
||||||
|
return host, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, mcnerror.ErrHostDoesNotExist{
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakeAPI) Remove(name string) error {
|
||||||
|
newHosts := []*host.Host{}
|
||||||
|
|
||||||
|
for _, host := range api.Hosts {
|
||||||
|
if name != host.Name {
|
||||||
|
newHosts = append(newHosts, host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api.Hosts = newHosts
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakeAPI) Save(host *host.Host) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func State(api libmachine.API, name string) state.State {
|
||||||
|
host, _ := api.Load(name)
|
||||||
|
machineState, _ := host.Driver.GetState()
|
||||||
|
return machineState
|
||||||
|
}
|
||||||
|
|
||||||
|
func Exists(api libmachine.API, name string) bool {
|
||||||
|
exists, _ := api.Exists(name)
|
||||||
|
return exists
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue