Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit 3f90d94

Browse files
committed
commands/commands: Get tests to pass
* commands/commands.go - Use package `github.com/lambda-linux/lambda-machine-local/commands/mcndirs` instead of `github.com/docker/machine/commands/mcndirs` - `var Commands = []cli.Command{}` and `commands := map[string](func() error){}` are empty. This will be populated in subsequent commits when we import commands * commands/commands_test.go - Removed tests + TestRunActionForeachMachine + TestPrintIPEmptyGivenLocalEngine + TestPrintIPPrintsGivenRemoteEngine We will add them back in subsequent commits - Add environment variable `BUGSNAG_ENABLE` so we can control invocation of bugsnag when running tests Tests can be run using, ``` $ go test -v -race -tags "" github.com/lambda-linux/lambda-machine-local/commands -run "Test*" $ BUGSNAG_ENABLE=1 go test -v -race -tags "" github.com/lambda-linux/lambda-machine-local/commands -run "Test*" ```
1 parent b9a7d06 commit 3f90d94

2 files changed

Lines changed: 8 additions & 322 deletions

File tree

commands/commands.go

Lines changed: 3 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88

99
"github.com/codegangsta/cli"
10-
"github.com/docker/machine/commands/mcndirs"
1110
"github.com/docker/machine/libmachine"
1211
"github.com/docker/machine/libmachine/crashreport"
1312
"github.com/docker/machine/libmachine/host"
@@ -16,6 +15,7 @@ import (
1615
"github.com/docker/machine/libmachine/mcnutils"
1716
"github.com/docker/machine/libmachine/persist"
1817
"github.com/docker/machine/libmachine/ssh"
18+
"github.com/lambda-linux/lambda-machine-local/commands/mcndirs"
1919
)
2020

2121
const (
@@ -192,211 +192,7 @@ func confirmInput(msg string) (bool, error) {
192192
return confirmed, nil
193193
}
194194

195-
var Commands = []cli.Command{
196-
{
197-
Name: "active",
198-
Usage: "Print which machine is active",
199-
Action: runCommand(cmdActive),
200-
Flags: []cli.Flag{
201-
cli.IntFlag{
202-
Name: "timeout, t",
203-
Usage: fmt.Sprintf("Timeout in seconds, default to %ds", activeDefaultTimeout),
204-
Value: activeDefaultTimeout,
205-
},
206-
},
207-
},
208-
{
209-
Name: "config",
210-
Usage: "Print the connection config for machine",
211-
Description: "Argument is a machine name.",
212-
Action: runCommand(cmdConfig),
213-
Flags: []cli.Flag{
214-
cli.BoolFlag{
215-
Name: "swarm",
216-
Usage: "Display the Swarm config instead of the Docker daemon",
217-
},
218-
},
219-
},
220-
{
221-
Flags: SharedCreateFlags,
222-
Name: "create",
223-
Usage: "Create a machine",
224-
Description: fmt.Sprintf("Run '%s create --driver name' to include the create flags for that driver in the help text.", os.Args[0]),
225-
Action: runCommand(cmdCreateOuter),
226-
SkipFlagParsing: true,
227-
},
228-
{
229-
Name: "env",
230-
Usage: "Display the commands to set up the environment for the Docker client",
231-
Description: "Argument is a machine name.",
232-
Action: runCommand(cmdEnv),
233-
Flags: []cli.Flag{
234-
cli.BoolFlag{
235-
Name: "swarm",
236-
Usage: "Display the Swarm config instead of the Docker daemon",
237-
},
238-
cli.StringFlag{
239-
Name: "shell",
240-
Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect",
241-
},
242-
cli.BoolFlag{
243-
Name: "unset, u",
244-
Usage: "Unset variables instead of setting them",
245-
},
246-
cli.BoolFlag{
247-
Name: "no-proxy",
248-
Usage: "Add machine IP to NO_PROXY environment variable",
249-
},
250-
},
251-
},
252-
{
253-
Name: "inspect",
254-
Usage: "Inspect information about a machine",
255-
Description: "Argument is a machine name.",
256-
Action: runCommand(cmdInspect),
257-
Flags: []cli.Flag{
258-
cli.StringFlag{
259-
Name: "format, f",
260-
Usage: "Format the output using the given go template.",
261-
Value: "",
262-
},
263-
},
264-
},
265-
{
266-
Name: "ip",
267-
Usage: "Get the IP address of a machine",
268-
Description: "Argument(s) are one or more machine names.",
269-
Action: runCommand(cmdIP),
270-
},
271-
{
272-
Name: "kill",
273-
Usage: "Kill a machine",
274-
Description: "Argument(s) are one or more machine names.",
275-
Action: runCommand(cmdKill),
276-
},
277-
{
278-
Name: "ls",
279-
Usage: "List machines",
280-
Action: runCommand(cmdLs),
281-
Flags: []cli.Flag{
282-
cli.BoolFlag{
283-
Name: "quiet, q",
284-
Usage: "Enable quiet mode",
285-
},
286-
cli.StringSliceFlag{
287-
Name: "filter",
288-
Usage: "Filter output based on conditions provided",
289-
Value: &cli.StringSlice{},
290-
},
291-
cli.IntFlag{
292-
Name: "timeout, t",
293-
Usage: fmt.Sprintf("Timeout in seconds, default to %ds", lsDefaultTimeout),
294-
Value: lsDefaultTimeout,
295-
},
296-
cli.StringFlag{
297-
Name: "format, f",
298-
Usage: "Pretty-print machines using a Go template",
299-
},
300-
},
301-
},
302-
{
303-
Name: "provision",
304-
Usage: "Re-provision existing machines",
305-
Action: runCommand(cmdProvision),
306-
},
307-
{
308-
Name: "regenerate-certs",
309-
Usage: "Regenerate TLS Certificates for a machine",
310-
Description: "Argument(s) are one or more machine names.",
311-
Action: runCommand(cmdRegenerateCerts),
312-
Flags: []cli.Flag{
313-
cli.BoolFlag{
314-
Name: "force, f",
315-
Usage: "Force rebuild and do not prompt",
316-
},
317-
},
318-
},
319-
{
320-
Name: "restart",
321-
Usage: "Restart a machine",
322-
Description: "Argument(s) are one or more machine names.",
323-
Action: runCommand(cmdRestart),
324-
},
325-
{
326-
Flags: []cli.Flag{
327-
cli.BoolFlag{
328-
Name: "force, f",
329-
Usage: "Remove local configuration even if machine cannot be removed, also implies an automatic yes (`-y`)",
330-
},
331-
cli.BoolFlag{
332-
Name: "y",
333-
Usage: "Assumes automatic yes to proceed with remove, without prompting further user confirmation",
334-
},
335-
},
336-
Name: "rm",
337-
Usage: "Remove a machine",
338-
Description: "Argument(s) are one or more machine names.",
339-
Action: runCommand(cmdRm),
340-
},
341-
{
342-
Name: "ssh",
343-
Usage: "Log into or run a command on a machine with SSH.",
344-
Description: "Arguments are [machine-name] [command]",
345-
Action: runCommand(cmdSSH),
346-
SkipFlagParsing: true,
347-
},
348-
{
349-
Name: "scp",
350-
Usage: "Copy files between machines",
351-
Description: "Arguments are [machine:][path] [machine:][path].",
352-
Action: runCommand(cmdScp),
353-
Flags: []cli.Flag{
354-
cli.BoolFlag{
355-
Name: "recursive, r",
356-
Usage: "Copy files recursively (required to copy directories)",
357-
},
358-
cli.BoolFlag{
359-
Name: "delta, d",
360-
Usage: "Reduce amount of data sent over network by sending only the differences (uses rsync)",
361-
},
362-
},
363-
},
364-
{
365-
Name: "start",
366-
Usage: "Start a machine",
367-
Description: "Argument(s) are one or more machine names.",
368-
Action: runCommand(cmdStart),
369-
},
370-
{
371-
Name: "status",
372-
Usage: "Get the status of a machine",
373-
Description: "Argument is a machine name.",
374-
Action: runCommand(cmdStatus),
375-
},
376-
{
377-
Name: "stop",
378-
Usage: "Stop a machine",
379-
Description: "Argument(s) are one or more machine names.",
380-
Action: runCommand(cmdStop),
381-
},
382-
{
383-
Name: "upgrade",
384-
Usage: "Upgrade a machine to the latest version of Docker",
385-
Description: "Argument(s) are one or more machine names.",
386-
Action: runCommand(cmdUpgrade),
387-
},
388-
{
389-
Name: "url",
390-
Usage: "Get the URL of a machine",
391-
Description: "Argument is a machine name.",
392-
Action: runCommand(cmdURL),
393-
},
394-
{
395-
Name: "version",
396-
Usage: "Show the Docker Machine version or a machine docker version",
397-
Action: runCommand(cmdVersion),
398-
},
399-
}
195+
var Commands = []cli.Command{}
400196

401197
func printIP(h *host.Host) func() error {
402198
return func() error {
@@ -415,16 +211,7 @@ func printIP(h *host.Host) func() error {
415211
// We run commands concurrently and communicate back an error if there was one.
416212
func machineCommand(actionName string, host *host.Host, errorChan chan<- error) {
417213
// TODO: These actions should have their own type.
418-
commands := map[string](func() error){
419-
"configureAuth": host.ConfigureAuth,
420-
"start": host.Start,
421-
"stop": host.Stop,
422-
"restart": host.Restart,
423-
"kill": host.Kill,
424-
"upgrade": host.Upgrade,
425-
"ip": printIP(host),
426-
"provision": host.Provision,
427-
}
214+
commands := map[string](func() error){}
428215

429216
log.Debugf("command=%s machine=%s", actionName, host.Name)
430217

commands/commands_test.go

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,121 +3,16 @@ package commands
33
import (
44
"errors"
55
"flag"
6+
"os"
67
"testing"
78

89
"github.com/codegangsta/cli"
9-
"github.com/docker/machine/commands/commandstest"
10-
"github.com/docker/machine/drivers/fakedriver"
1110
"github.com/docker/machine/libmachine"
1211
"github.com/docker/machine/libmachine/crashreport"
13-
"github.com/docker/machine/libmachine/host"
14-
"github.com/docker/machine/libmachine/hosttest"
1512
"github.com/docker/machine/libmachine/mcnerror"
16-
"github.com/docker/machine/libmachine/provision"
17-
"github.com/docker/machine/libmachine/state"
1813
"github.com/stretchr/testify/assert"
1914
)
2015

21-
func TestRunActionForeachMachine(t *testing.T) {
22-
defer provision.SetDetector(&provision.StandardDetector{})
23-
provision.SetDetector(&provision.FakeDetector{
24-
Provisioner: provision.NewNetstatProvisioner(),
25-
})
26-
27-
// Assume a bunch of machines in randomly started or
28-
// stopped states.
29-
machines := []*host.Host{
30-
{
31-
Name: "foo",
32-
DriverName: "fakedriver",
33-
Driver: &fakedriver.Driver{
34-
MockState: state.Running,
35-
},
36-
},
37-
{
38-
Name: "bar",
39-
DriverName: "fakedriver",
40-
Driver: &fakedriver.Driver{
41-
MockState: state.Stopped,
42-
},
43-
},
44-
{
45-
Name: "baz",
46-
// Ssh, don't tell anyone but this
47-
// driver only _thinks_ it's named
48-
// virtualbox... (to test serial actions)
49-
// It's actually FakeDriver!
50-
DriverName: "virtualbox",
51-
Driver: &fakedriver.Driver{
52-
MockState: state.Stopped,
53-
},
54-
},
55-
{
56-
Name: "spam",
57-
DriverName: "virtualbox",
58-
Driver: &fakedriver.Driver{
59-
MockState: state.Running,
60-
},
61-
},
62-
{
63-
Name: "eggs",
64-
DriverName: "fakedriver",
65-
Driver: &fakedriver.Driver{
66-
MockState: state.Stopped,
67-
},
68-
},
69-
{
70-
Name: "ham",
71-
DriverName: "fakedriver",
72-
Driver: &fakedriver.Driver{
73-
MockState: state.Running,
74-
},
75-
},
76-
}
77-
78-
runActionForeachMachine("start", machines)
79-
80-
for _, machine := range machines {
81-
machineState, _ := machine.Driver.GetState()
82-
83-
assert.Equal(t, state.Running, machineState)
84-
}
85-
86-
runActionForeachMachine("stop", machines)
87-
88-
for _, machine := range machines {
89-
machineState, _ := machine.Driver.GetState()
90-
91-
assert.Equal(t, state.Stopped, machineState)
92-
}
93-
}
94-
95-
func TestPrintIPEmptyGivenLocalEngine(t *testing.T) {
96-
stdoutGetter := commandstest.NewStdoutGetter()
97-
defer stdoutGetter.Stop()
98-
99-
host, _ := hosttest.GetDefaultTestHost()
100-
err := printIP(host)()
101-
102-
assert.NoError(t, err)
103-
assert.Equal(t, "\n", stdoutGetter.Output())
104-
}
105-
106-
func TestPrintIPPrintsGivenRemoteEngine(t *testing.T) {
107-
stdoutGetter := commandstest.NewStdoutGetter()
108-
defer stdoutGetter.Stop()
109-
110-
host, _ := hosttest.GetDefaultTestHost()
111-
host.Driver = &fakedriver.Driver{
112-
MockState: state.Running,
113-
MockIP: "1.2.3.4",
114-
}
115-
err := printIP(host)()
116-
117-
assert.NoError(t, err)
118-
assert.Equal(t, "1.2.3.4\n", stdoutGetter.Output())
119-
}
120-
12116
func TestConsolidateError(t *testing.T) {
12217
cases := []struct {
12318
inputErrs []error
@@ -210,6 +105,10 @@ func TestReturnExitCode1onError(t *testing.T) {
210105
}
211106

212107
func TestReturnExitCode3onErrorDuringPreCreate(t *testing.T) {
108+
if os.Getenv("BUGSNAG_ENABLE") == "" {
109+
t.Skip("skipping test; $BUGSNAG_ENABLE not set")
110+
}
111+
213112
command := func(commandLine CommandLine, api libmachine.API) error {
214113
return crashreport.CrashError{
215114
Cause: mcnerror.ErrDuringPreCreate{

0 commit comments

Comments
 (0)