Skip to content

Commit a8265e7

Browse files
committed
cli/command/volume: TestVolumeCreateWithFlags: minor fixes
- assert unhandled error - reset command-args to prevent test failing when running from pre-compiled test-binary - use a const and a slightly more unique name for the volume-name - discard stdout/stderr output Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8b5e553 commit a8265e7

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

cli/command/volume/create_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ func TestVolumeCreateWithName(t *testing.T) {
104104
}
105105

106106
func TestVolumeCreateWithFlags(t *testing.T) {
107-
expectedDriver := "foo"
107+
const name = "random-generated-name"
108+
const expectedDriver = "foo-volume-driver"
108109
expectedOpts := map[string]string{
109110
"bar": "1",
110111
"baz": "baz",
@@ -113,7 +114,6 @@ func TestVolumeCreateWithFlags(t *testing.T) {
113114
"lbl1": "v1",
114115
"lbl2": "v2",
115116
}
116-
name := "banana"
117117

118118
cli := test.NewFakeCli(&fakeClient{
119119
volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) {
@@ -136,13 +136,16 @@ func TestVolumeCreateWithFlags(t *testing.T) {
136136
})
137137

138138
cmd := newCreateCommand(cli)
139-
cmd.Flags().Set("driver", "foo")
140-
cmd.Flags().Set("opt", "bar=1")
141-
cmd.Flags().Set("opt", "baz=baz")
142-
cmd.Flags().Set("label", "lbl1=v1")
143-
cmd.Flags().Set("label", "lbl2=v2")
139+
cmd.SetOut(io.Discard)
140+
cmd.SetErr(io.Discard)
141+
cmd.SetArgs([]string{})
142+
assert.Check(t, cmd.Flags().Set("driver", expectedDriver))
143+
assert.Check(t, cmd.Flags().Set("opt", "bar=1"))
144+
assert.Check(t, cmd.Flags().Set("opt", "baz=baz"))
145+
assert.Check(t, cmd.Flags().Set("label", "lbl1=v1"))
146+
assert.Check(t, cmd.Flags().Set("label", "lbl2=v2"))
144147
assert.NilError(t, cmd.Execute())
145-
assert.Check(t, is.Equal(name, strings.TrimSpace(cli.OutBuffer().String())))
148+
assert.Check(t, is.Equal(strings.TrimSpace(cli.OutBuffer().String()), name))
146149
}
147150

148151
func TestVolumeCreateCluster(t *testing.T) {

0 commit comments

Comments
 (0)