cli/command: remove dot-imports and unhandled errors
Please the linters in preparation of updating golangci-lint;
- remove dot-imports
- add some checks for unhandled errors
- replace some fixed-value variables for consts
cli/command/image/build/context.go:238:17: G107: Potential HTTP request made with variable url (gosec)
if resp, err = http.Get(url); err != nil {
^
cli/command/idresolver/idresolver_test.go:7:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/registry_test.go:7:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/cli/command" // Prevents a circular import with "github.com/docker/cli/internal/test"
^
cli/command/task/print_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/swarm/update_test.go:10:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/swarm/unlock_key_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/swarm/join_token_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/node/list_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/node/promote_test.go:8:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/node/demote_test.go:8:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions
^
cli/command/node/ps_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/node/update_test.go:8:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/node/inspect_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions
^
cli/command/secret/ls_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/secret/inspect_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/volume/inspect_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/volume/list_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/config/inspect_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/config/ls_test.go:11:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/network/list_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders"
^
cli/command/container/list_test.go:10:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/service/list_test.go:12:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders"
^
cli/command/service/client_test.go:6:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/stack/list_test.go:8:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/stack/services_test.go:9:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
cli/command/stack/ps_test.go:10:2: dot-imports: should not use dot imports (revive)
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 594aeb390a)
Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
committed by
Cory Snider
parent
867baaff66
commit
3e271deeca
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
|
||||
"github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/pkg/errors"
|
||||
@@ -59,7 +59,7 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||
)
|
||||
cmd.SetArgs(tc.args)
|
||||
for key, value := range tc.flags {
|
||||
cmd.Flags().Set(key, value)
|
||||
assert.Check(t, cmd.Flags().Set(key, value))
|
||||
}
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
@@ -80,14 +80,14 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||
if volumeID != "foo" {
|
||||
return volume.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID)
|
||||
}
|
||||
return *Volume(), nil
|
||||
return *builders.Volume(), nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple-volume-with-labels",
|
||||
args: []string{"foo", "bar"},
|
||||
volumeInspectFunc: func(volumeID string) (volume.Volume, error) {
|
||||
return *Volume(VolumeName(volumeID), VolumeLabels(map[string]string{
|
||||
return *builders.Volume(builders.VolumeName(volumeID), builders.VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})), nil
|
||||
},
|
||||
@@ -106,7 +106,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||
|
||||
func TestVolumeInspectWithFormat(t *testing.T) {
|
||||
volumeInspectFunc := func(volumeID string) (volume.Volume, error) {
|
||||
return *Volume(VolumeLabels(map[string]string{
|
||||
return *builders.Volume(builders.VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})), nil
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func TestVolumeInspectWithFormat(t *testing.T) {
|
||||
})
|
||||
cmd := newInspectCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
cmd.Flags().Set("format", tc.format)
|
||||
assert.Check(t, cmd.Flags().Set("format", tc.format))
|
||||
assert.NilError(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli/config/configfile"
|
||||
"github.com/docker/cli/internal/test"
|
||||
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
|
||||
"github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/pkg/errors"
|
||||
@@ -40,7 +40,7 @@ func TestVolumeListErrors(t *testing.T) {
|
||||
)
|
||||
cmd.SetArgs(tc.args)
|
||||
for key, value := range tc.flags {
|
||||
cmd.Flags().Set(key, value)
|
||||
assert.Check(t, cmd.Flags().Set(key, value))
|
||||
}
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
@@ -53,9 +53,9 @@ func TestVolumeListWithoutFormat(t *testing.T) {
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
builders.Volume(),
|
||||
builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")),
|
||||
builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})),
|
||||
},
|
||||
@@ -72,9 +72,9 @@ func TestVolumeListWithConfigFormat(t *testing.T) {
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
builders.Volume(),
|
||||
builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")),
|
||||
builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})),
|
||||
},
|
||||
@@ -94,9 +94,9 @@ func TestVolumeListWithFormat(t *testing.T) {
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
builders.Volume(),
|
||||
builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")),
|
||||
builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})),
|
||||
},
|
||||
@@ -104,7 +104,7 @@ func TestVolumeListWithFormat(t *testing.T) {
|
||||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")
|
||||
assert.Check(t, cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}"))
|
||||
assert.NilError(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "volume-list-with-format.golden")
|
||||
}
|
||||
@@ -114,15 +114,15 @@ func TestVolumeListSortOrder(t *testing.T) {
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(VolumeName("volume-2-foo")),
|
||||
Volume(VolumeName("volume-10-foo")),
|
||||
Volume(VolumeName("volume-1-foo")),
|
||||
builders.Volume(builders.VolumeName("volume-2-foo")),
|
||||
builders.Volume(builders.VolumeName("volume-10-foo")),
|
||||
builders.Volume(builders.VolumeName("volume-1-foo")),
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
cmd.Flags().Set("format", "{{ .Name }}")
|
||||
assert.Check(t, cmd.Flags().Set("format", "{{ .Name }}"))
|
||||
assert.NilError(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "volume-list-sort.golden")
|
||||
}
|
||||
@@ -223,14 +223,14 @@ func TestClusterVolumeList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Volume(VolumeName("volume-local-1")),
|
||||
builders.Volume(builders.VolumeName("volume-local-1")),
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
})
|
||||
|
||||
cmd := newListCommand(cli)
|
||||
cmd.Flags().Set("cluster", "true")
|
||||
assert.Check(t, cmd.Flags().Set("cluster", "true"))
|
||||
assert.NilError(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "volume-cluster-volume-list.golden")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user