forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
89 lines (69 loc) · 2.35 KB
/
version_test.go
File metadata and controls
89 lines (69 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package commands
import (
"errors"
"testing"
"bytes"
"github.com/docker/machine/commands/commandstest"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/libmachinetest"
"github.com/docker/machine/libmachine/mcndockerclient"
"github.com/stretchr/testify/assert"
)
func TestCmdVersion(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{}
api := &libmachinetest.FakeAPI{}
err := cmdVersion(commandLine, api)
assert.True(t, commandLine.VersionShown)
assert.NoError(t, err)
}
func TestCmdVersionTooManyNames(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"machine1", "machine2"},
}
api := &libmachinetest.FakeAPI{}
err := cmdVersion(commandLine, api)
assert.EqualError(t, err, "Error: Expected one machine name as an argument")
}
func TestCmdVersionNotFound(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"unknown"},
}
api := &libmachinetest.FakeAPI{}
err := cmdVersion(commandLine, api)
assert.EqualError(t, err, `Docker machine "unknown" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.`)
}
func TestCmdVersionOnHost(t *testing.T) {
defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner)
mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Version: "1.9.1"}
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"machine"},
}
api := &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "machine",
},
},
}
out := &bytes.Buffer{}
err := printVersion(commandLine, api, out)
assert.NoError(t, err)
assert.Equal(t, "1.9.1\n", out.String())
}
func TestCmdVersionFailure(t *testing.T) {
defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner)
mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Err: errors.New("connection failure")}
commandLine := &commandstest.FakeCommandLine{
CliArgs: []string{"machine"},
}
api := &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "machine",
},
},
}
out := &bytes.Buffer{}
err := printVersion(commandLine, api, out)
assert.EqualError(t, err, "connection failure")
}