(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func TestVolumeCreateWithName(t *testing.T) { |
| 64 | const name = "my-volume-name" |
| 65 | cli := test.NewFakeCli(&fakeClient{ |
| 66 | volumeCreateFunc: func(options client.VolumeCreateOptions) (client.VolumeCreateResult, error) { |
| 67 | if options.Name != name { |
| 68 | return client.VolumeCreateResult{}, fmt.Errorf("expected name %q, got %q", name, options.Name) |
| 69 | } |
| 70 | return client.VolumeCreateResult{ |
| 71 | Volume: volume.Volume{Name: options.Name}, |
| 72 | }, nil |
| 73 | }, |
| 74 | }) |
| 75 | |
| 76 | buf := cli.OutBuffer() |
| 77 | t.Run("using-flags", func(t *testing.T) { |
| 78 | cmd := newCreateCommand(cli) |
| 79 | cmd.SetOut(io.Discard) |
| 80 | cmd.SetErr(io.Discard) |
| 81 | cmd.SetArgs([]string{}) |
| 82 | assert.Check(t, cmd.Flags().Set("name", name)) |
| 83 | assert.NilError(t, cmd.Execute()) |
| 84 | assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), name)) |
| 85 | }) |
| 86 | |
| 87 | buf.Reset() |
| 88 | t.Run("using-args", func(t *testing.T) { |
| 89 | cmd := newCreateCommand(cli) |
| 90 | cmd.SetOut(io.Discard) |
| 91 | cmd.SetErr(io.Discard) |
| 92 | cmd.SetArgs([]string{name}) |
| 93 | assert.NilError(t, cmd.Execute()) |
| 94 | assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), name)) |
| 95 | }) |
| 96 | |
| 97 | buf.Reset() |
| 98 | t.Run("using-both", func(t *testing.T) { |
| 99 | cmd := newCreateCommand(cli) |
| 100 | cmd.SetOut(io.Discard) |
| 101 | cmd.SetErr(io.Discard) |
| 102 | cmd.SetArgs([]string{name}) |
| 103 | assert.Check(t, cmd.Flags().Set("name", name)) |
| 104 | err := cmd.Execute() |
| 105 | assert.Check(t, is.Error(err, `conflicting options: cannot specify a volume-name through both --name and as a positional arg`)) |
| 106 | assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), "")) |
| 107 | }) |
| 108 | } |
| 109 | |
| 110 | func TestVolumeCreateWithFlags(t *testing.T) { |
| 111 | const name = "random-generated-name" |
nothing calls this directly
no test coverage detected
searching dependent graphs…