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/host"
|
||||
"github.com/docker/machine/libmachine/libmachinetest"
|
||||
"github.com/docker/machine/libmachine/persist/persisttest"
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -118,11 +117,9 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -156,11 +153,9 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -194,11 +189,9 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -232,11 +225,9 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -270,14 +261,12 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
Driver: &fakedriver.Driver{
|
||||
MockState: state.Running,
|
||||
MockIP: "1.2.3.4",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
Driver: &fakedriver.Driver{
|
||||
MockState: state.Running,
|
||||
MockIP: "1.2.3.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -316,14 +305,12 @@ func TestShellCfgSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
Driver: &fakedriver.Driver{
|
||||
MockState: state.Running,
|
||||
MockIP: "1.2.3.4",
|
||||
},
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "quux",
|
||||
Driver: &fakedriver.Driver{
|
||||
MockState: state.Running,
|
||||
MockIP: "1.2.3.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -431,9 +418,7 @@ func TestShellCfgUnset(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{},
|
||||
connChecker: &FakeConnChecker{
|
||||
DockerHost: "tcp://1.2.3.4:2376",
|
||||
AuthOptions: nil,
|
||||
|
@ -485,9 +470,7 @@ func TestShellCfgUnset(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{
|
||||
FakeStore: &persisttest.FakeStore{},
|
||||
},
|
||||
api: &libmachinetest.FakeAPI{},
|
||||
connChecker: &FakeConnChecker{
|
||||
DockerHost: "tcp://1.2.3.4:2376",
|
||||
AuthOptions: nil,
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
"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 TestCmdIPMissingMachineName(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{}
|
||||
api := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdURL(commandLine, api)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestCmdIP(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machine"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machine",
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
"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 TestCmdKillMissingMachineName(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{}
|
||||
api := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdKill(commandLine, api)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestCmdKill(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToKill1", "machineToKill2"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToKill1",
|
||||
|
@ -49,7 +50,7 @@ func TestCmdKill(t *testing.T) {
|
|||
err := cmdKill(commandLine, api)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToKill1"))
|
||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToKill2"))
|
||||
assert.Equal(t, state.Running, commandstest.State(api, "machine"))
|
||||
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill1"))
|
||||
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill2"))
|
||||
assert.Equal(t, state.Running, libmachinetest.State(api, "machine"))
|
||||
}
|
||||
|
|
|
@ -6,12 +6,13 @@ import (
|
|||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCmdRmMissingMachineName(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{}
|
||||
api := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdRm(commandLine, api)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestCmdRm(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToRemove1",
|
||||
|
@ -43,7 +44,7 @@ func TestCmdRm(t *testing.T) {
|
|||
err := cmdRm(commandLine, api)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.False(t, commandstest.Exists(api, "machineToRemove1"))
|
||||
assert.False(t, commandstest.Exists(api, "machineToRemove2"))
|
||||
assert.True(t, commandstest.Exists(api, "machine"))
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove1"))
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove2"))
|
||||
assert.True(t, libmachinetest.Exists(api, "machine"))
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
"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 TestCmdStopMissingMachineName(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{}
|
||||
api := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdStop(commandLine, api)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestCmdStop(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToStop1", "machineToStop2"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToStop1",
|
||||
|
@ -49,7 +50,7 @@ func TestCmdStop(t *testing.T) {
|
|||
err := cmdStop(commandLine, api)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToStop1"))
|
||||
assert.Equal(t, state.Stopped, commandstest.State(api, "machineToStop2"))
|
||||
assert.Equal(t, state.Running, commandstest.State(api, "machine"))
|
||||
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToStop1"))
|
||||
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToStop2"))
|
||||
assert.Equal(t, state.Running, libmachinetest.State(api, "machine"))
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
"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 := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdURL(commandLine, api)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestCmdURLTooManyNames(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{}
|
||||
api := &libmachinetest.FakeAPI{}
|
||||
|
||||
err := cmdURL(commandLine, api)
|
||||
|
||||
|
@ -34,7 +35,7 @@ func TestCmdURL(t *testing.T) {
|
|||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machine"},
|
||||
}
|
||||
api := &commandstest.FakeLibmachineAPI{
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machine",
|
||||
|
|
|
@ -1,26 +1,80 @@
|
|||
package libmachinetest
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"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 {
|
||||
*persisttest.FakeStore
|
||||
FakeNewDriver drivers.Driver
|
||||
FakeNewHost *host.Host
|
||||
NewPluginDriverErr, NewHostErr, CreateErr error
|
||||
Hosts []*host.Host
|
||||
}
|
||||
|
||||
func (fapi *FakeAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) {
|
||||
return fapi.FakeNewDriver, fapi.NewPluginDriverErr
|
||||
func (api *FakeAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (fapi *FakeAPI) NewHost(drivers.Driver) (*host.Host, error) {
|
||||
return fapi.FakeNewHost, fapi.NewHostErr
|
||||
func (api *FakeAPI) NewHost(driver drivers.Driver) (*host.Host, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (fapi *FakeAPI) Create(h *host.Host) error {
|
||||
return fapi.CreateErr
|
||||
func (api *FakeAPI) Create(h *host.Host) error {
|
||||
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