2017-04-01 03:07:22 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
cli/command/secret: fakeClient: include context in fake client (revive)
I could either remove the name for these contexts, or make the fake functions
more accurately reflect the actual implementation (decided to go for the latter
one)
cli/command/secret/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/secret/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
^
cli/command/secret/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
^
cli/command/secret/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9dd012aa5df1c7b076f53d6cd2c328de0ea3b0f4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 10:22:06 -04:00
|
|
|
"context"
|
2022-02-25 08:30:27 -05:00
|
|
|
"io"
|
2017-04-01 03:07:22 -04:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-21 16:30:09 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2017-04-01 03:07:22 -04:00
|
|
|
"github.com/pkg/errors"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-04-01 03:07:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretRemoveErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
args []string
|
cli/command/secret: fakeClient: include context in fake client (revive)
I could either remove the name for these contexts, or make the fake functions
more accurately reflect the actual implementation (decided to go for the latter
one)
cli/command/secret/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/secret/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
^
cli/command/secret/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
^
cli/command/secret/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9dd012aa5df1c7b076f53d6cd2c328de0ea3b0f4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 10:22:06 -04:00
|
|
|
secretRemoveFunc func(context.Context, string) error
|
2017-04-01 03:07:22 -04:00
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{},
|
2017-08-12 12:25:38 -04:00
|
|
|
expectedError: "requires at least 1 argument.",
|
2017-04-01 03:07:22 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"foo"},
|
cli/command/secret: fakeClient: include context in fake client (revive)
I could either remove the name for these contexts, or make the fake functions
more accurately reflect the actual implementation (decided to go for the latter
one)
cli/command/secret/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/secret/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
^
cli/command/secret/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
^
cli/command/secret/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9dd012aa5df1c7b076f53d6cd2c328de0ea3b0f4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 10:22:06 -04:00
|
|
|
secretRemoveFunc: func(_ context.Context, name string) error {
|
2017-04-01 03:07:22 -04:00
|
|
|
return errors.Errorf("error removing secret")
|
|
|
|
},
|
|
|
|
expectedError: "error removing secret",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
cmd := newSecretRemoveCommand(
|
2017-08-16 12:53:41 -04:00
|
|
|
test.NewFakeCli(&fakeClient{
|
2017-04-01 03:07:22 -04:00
|
|
|
secretRemoveFunc: tc.secretRemoveFunc,
|
2017-08-16 12:53:41 -04:00
|
|
|
}),
|
2017-04-01 03:07:22 -04:00
|
|
|
)
|
|
|
|
cmd.SetArgs(tc.args)
|
2022-02-25 08:30:27 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2018-03-06 14:03:47 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2017-04-01 03:07:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretRemoveWithName(t *testing.T) {
|
|
|
|
names := []string{"foo", "bar"}
|
|
|
|
var removedSecrets []string
|
2017-08-16 12:53:41 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
cli/command/secret: fakeClient: include context in fake client (revive)
I could either remove the name for these contexts, or make the fake functions
more accurately reflect the actual implementation (decided to go for the latter
one)
cli/command/secret/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/secret/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
^
cli/command/secret/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
^
cli/command/secret/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9dd012aa5df1c7b076f53d6cd2c328de0ea3b0f4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 10:22:06 -04:00
|
|
|
secretRemoveFunc: func(_ context.Context, name string) error {
|
2017-04-01 03:07:22 -04:00
|
|
|
removedSecrets = append(removedSecrets, name)
|
|
|
|
return nil
|
|
|
|
},
|
2017-08-16 12:53:41 -04:00
|
|
|
})
|
2017-04-01 03:07:22 -04:00
|
|
|
cmd := newSecretRemoveCommand(cli)
|
|
|
|
cmd.SetArgs(names)
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
|
|
|
|
assert.Check(t, is.DeepEqual(names, removedSecrets))
|
2017-04-01 03:07:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretRemoveContinueAfterError(t *testing.T) {
|
|
|
|
names := []string{"foo", "bar"}
|
|
|
|
var removedSecrets []string
|
|
|
|
|
2017-08-16 12:53:41 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
cli/command/secret: fakeClient: include context in fake client (revive)
I could either remove the name for these contexts, or make the fake functions
more accurately reflect the actual implementation (decided to go for the latter
one)
cli/command/secret/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
^
cli/command/secret/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
^
cli/command/secret/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
^
cli/command/secret/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 9dd012aa5df1c7b076f53d6cd2c328de0ea3b0f4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-03-30 10:22:06 -04:00
|
|
|
secretRemoveFunc: func(_ context.Context, name string) error {
|
2017-04-01 03:07:22 -04:00
|
|
|
removedSecrets = append(removedSecrets, name)
|
|
|
|
if name == "foo" {
|
|
|
|
return errors.Errorf("error removing secret: %s", name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2017-08-16 12:53:41 -04:00
|
|
|
})
|
2017-04-01 03:07:22 -04:00
|
|
|
|
|
|
|
cmd := newSecretRemoveCommand(cli)
|
2022-02-25 08:30:27 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2017-04-01 03:07:22 -04:00
|
|
|
cmd.SetArgs(names)
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, cmd.Execute(), "error removing secret: foo")
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.DeepEqual(names, removedSecrets))
|
2017-04-01 03:07:22 -04:00
|
|
|
}
|