|
| 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" |
| 9 | + "github.com/docker/machine/libmachine/auth" |
| 10 | + "github.com/docker/machine/libmachine/engine" |
| 11 | + "github.com/docker/machine/libmachine/host" |
| 12 | + "github.com/docker/machine/libmachine/libmachinetest" |
| 13 | + "github.com/docker/machine/libmachine/provision" |
| 14 | + "github.com/docker/machine/libmachine/swarm" |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +func TestCmdProvision(t *testing.T) { |
| 19 | + testCases := []struct { |
| 20 | + commandLine CommandLine |
| 21 | + api libmachine.API |
| 22 | + expectedErr error |
| 23 | + }{ |
| 24 | + { |
| 25 | + commandLine: &commandstest.FakeCommandLine{ |
| 26 | + CliArgs: []string{"foo", "bar"}, |
| 27 | + }, |
| 28 | + api: &libmachinetest.FakeAPI{ |
| 29 | + Hosts: []*host.Host{ |
| 30 | + { |
| 31 | + Name: "foo", |
| 32 | + Driver: &fakedriver.Driver{}, |
| 33 | + HostOptions: &host.Options{ |
| 34 | + EngineOptions: &engine.Options{}, |
| 35 | + AuthOptions: &auth.Options{}, |
| 36 | + SwarmOptions: &swarm.Options{}, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + Name: "bar", |
| 41 | + Driver: &fakedriver.Driver{}, |
| 42 | + HostOptions: &host.Options{ |
| 43 | + EngineOptions: &engine.Options{}, |
| 44 | + AuthOptions: &auth.Options{}, |
| 45 | + SwarmOptions: &swarm.Options{}, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + expectedErr: nil, |
| 51 | + }, |
| 52 | + } |
| 53 | + |
| 54 | + provision.SetDetector(&provision.FakeDetector{ |
| 55 | + Provisioner: provision.NewFakeProvisioner(nil), |
| 56 | + }) |
| 57 | + |
| 58 | + // fakeprovisioner always returns "true" for compatible host, so we |
| 59 | + // just need to register it. |
| 60 | + provision.Register("fakeprovisioner", &provision.RegisteredProvisioner{ |
| 61 | + New: provision.NewFakeProvisioner, |
| 62 | + }) |
| 63 | + |
| 64 | + for _, tc := range testCases { |
| 65 | + assert.Equal(t, tc.expectedErr, cmdProvision(tc.commandLine, tc.api)) |
| 66 | + } |
| 67 | +} |
0 commit comments