Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format code with gofumpt #3794

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cli-plugins/manager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/spf13/cobra"
)

var (
pluginNameRe = regexp.MustCompile("^[a-z][a-z0-9]*$")
)
var pluginNameRe = regexp.MustCompile("^[a-z][a-z0-9]*$")

// Plugin represents a potential plugin with all it's metadata.
type Plugin struct {
Expand Down
1 change: 1 addition & 0 deletions cli-plugins/manager/suffix_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package manager
func trimExeSuffix(s string) (string, error) {
return s, nil
}

func addExeSuffix(s string) string {
return s
}
1 change: 0 additions & 1 deletion cli/command/checkpoint/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory")

return cmd

}

func runList(dockerCli command.Cli, container string, opts listOptions) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *fakeClient) NegotiateAPIVersionPing(types.Ping) {
func TestInitializeFromClient(t *testing.T) {
defaultVersion := "v1.55"

var testcases = []struct {
testcases := []struct {
doc string
pingFunc func() (types.Ping, error)
expectedServer ServerInfo
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestInitializeFromClientHangs(t *testing.T) {
func TestExperimentalCLI(t *testing.T) {
defaultVersion := "v1.55"

var testcases = []struct {
testcases := []struct {
doc string
configfile string
}{
Expand Down
3 changes: 2 additions & 1 deletion cli/command/config/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestConfigCreateErrors(t *testing.T) {
args: []string{"too_few"},
expectedError: "requires exactly 2 arguments",
},
{args: []string{"too", "many", "arguments"},
{
args: []string{"too", "many", "arguments"},
expectedError: "requires exactly 2 arguments",
},
{
Expand Down
30 changes: 20 additions & 10 deletions cli/command/config/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,39 @@ func TestConfigContextFormatWrite(t *testing.T) {
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
},
// Table format
{formatter.Context{Format: NewFormat("table", false)},
{
formatter.Context{Format: NewFormat("table", false)},
`ID NAME CREATED UPDATED
1 passwords Less than a second ago Less than a second ago
2 id_rsa Less than a second ago Less than a second ago
`},
{formatter.Context{Format: NewFormat("table {{.Name}}", true)},
`,
},
{
formatter.Context{Format: NewFormat("table {{.Name}}", true)},
`NAME
passwords
id_rsa
`},
{formatter.Context{Format: NewFormat("{{.ID}}-{{.Name}}", false)},
`,
},
{
formatter.Context{Format: NewFormat("{{.ID}}-{{.Name}}", false)},
`1-passwords
2-id_rsa
`},
`,
},
}

configs := []swarm.Config{
{ID: "1",
{
ID: "1",
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}}},
{ID: "2",
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}},
},
{
ID: "2",
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}},
},
}
for _, tc := range cases {
tc := tc
Expand Down
1 change: 0 additions & 1 deletion cli/command/config/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ func RunConfigInspect(dockerCli command.Cli, opts InspectOptions) error {
return cli.StatusError{StatusCode: 1, Status: err.Error()}
}
return nil

}
4 changes: 2 additions & 2 deletions cli/command/container/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestRunCopyWithInvalidArguments(t *testing.T) {
var testcases = []struct {
testcases := []struct {
doc string
options copyOptions
expectedErr string
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestRunCopyToContainerSourceDoesNotExist(t *testing.T) {
}

func TestSplitCpArg(t *testing.T) {
var testcases = []struct {
testcases := []struct {
doc string
path string
os string
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestParseExecNoSuchFile(t *testing.T) {
}

func TestRunExec(t *testing.T) {
var testcases = []struct {
testcases := []struct {
doc string
options ExecOptions
client fakeClient
Expand Down
2 changes: 0 additions & 2 deletions cli/command/container/formatter_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func NewDiffFormat(source string) formatter.Format {

// DiffFormatWrite writes formatted diff using the Context
func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeResponseItem) error {

render := func(format func(subContext formatter.SubContext) error) error {
for _, change := range changes {
if err := format(&diffContext{c: change}); err != nil {
Expand Down Expand Up @@ -65,7 +64,6 @@ func (d *diffContext) Type() string {
kind = "D"
}
return kind

}

func (d *diffContext) Path() string {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRunLogs(t *testing.T) {
}, nil
}

var testcases = []struct {
testcases := []struct {
doc string
options *logsOptions
client fakeClient
Expand Down
6 changes: 2 additions & 4 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"github.com/spf13/pflag"
)

var (
deviceCgroupRuleRegexp = regexp.MustCompile(`^[acb] ([0-9]+|\*):([0-9]+|\*) [rwm]{1,3}$`)
)
var deviceCgroupRuleRegexp = regexp.MustCompile(`^[acb] ([0-9]+|\*):([0-9]+|\*) [rwm]{1,3}$`)

// containerOptions is a data object with all the options for creating a container
type containerOptions struct {
Expand Down Expand Up @@ -978,7 +976,7 @@ func validateDeviceCgroupRule(val string) (string, error) {
// validDeviceMode checks if the mode for device is valid or not.
// Valid mode is a composition of r (read), w (write), and m (mknod).
func validDeviceMode(mode string) bool {
var legalDeviceMode = map[rune]bool{
legalDeviceMode := map[rune]bool{
'r': true,
'w': true,
'm': true,
Expand Down
4 changes: 0 additions & 4 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func TestParseRunWithInvalidArgs(t *testing.T) {

//nolint:gocyclo
func TestParseWithVolumes(t *testing.T) {

// A single volume
arr, tryit := setupPlatformVolume([]string{`/tmp`}, []string{`c:\tmp`})
if config, hostConfig := mustParse(t, tryit); hostConfig.Binds != nil {
Expand Down Expand Up @@ -252,7 +251,6 @@ func TestParseWithVolumes(t *testing.T) {
t.Fatalf("Error parsing %s. Should have a single bind mount and no volumes", arr[0])
}
}

}

// setupPlatformVolume takes two arrays of volume specs - a Unix style
Expand Down Expand Up @@ -453,7 +451,6 @@ func TestParseDevice(t *testing.T) {
t.Fatalf("Expected %v, got %v", deviceMapping, hostconfig.Devices)
}
}

}

func TestParseNetworkConfig(t *testing.T) {
Expand Down Expand Up @@ -956,7 +953,6 @@ func TestConvertToStandardNotation(t *testing.T) {

for key, ports := range valid {
convertedPorts, err := convertToStandardNotation(ports)

if err != nil {
assert.NilError(t, err)
}
Expand Down
1 change: 0 additions & 1 deletion cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
}

close, err := attachContainer(ctx, dockerCli, &errCh, config, createResponse.ID)

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion cli/command/container/signals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ func TestForwardSignals(t *testing.T) {
case <-timer.C:
t.Fatal("timeout waiting for signal to be processed")
}

}
1 change: 0 additions & 1 deletion cli/command/context/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ func TestShow(t *testing.T) {
cli.OutBuffer().Reset()
assert.NilError(t, runShow(cli))
golden.Assert(t, cli.OutBuffer().String(), "show.golden")

}
21 changes: 12 additions & 9 deletions cli/command/formatter/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ func TestContainerPsContext(t *testing.T) {
{types.Container{Image: "ubuntu"}, true, "ubuntu", ctx.Image},
{types.Container{Image: "verylongimagename"}, true, "verylongimagename", ctx.Image},
{types.Container{Image: "verylongimagename"}, false, "verylongimagename", ctx.Image},
{types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
{
types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
true,
"a5a665ff33ec",
ctx.Image,
},
{types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
{
types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
false,
"a5a665ff33eced1e0803148700880edab4",
ctx.Image,
Expand Down Expand Up @@ -446,7 +448,8 @@ func TestDisplayablePorts(t *testing.T) {
Type: "tcp",
},
},
"9988/tcp"},
"9988/tcp",
},
{
[]types.Port{
{
Expand Down
2 changes: 0 additions & 2 deletions cli/command/formatter/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ func (c *diskUsageImagesContext) Active() string {

func (c *diskUsageImagesContext) Size() string {
return units.HumanSize(float64(c.totalSize))

}

func (c *diskUsageImagesContext) Reclaimable() string {
Expand Down Expand Up @@ -391,7 +390,6 @@ func (c *diskUsageVolumesContext) TotalCount() string {
}

func (c *diskUsageVolumesContext) Active() string {

used := 0
for _, v := range c.volumes {
if v.UsageData.RefCount > 0 {
Expand Down
3 changes: 2 additions & 1 deletion cli/command/formatter/disk_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func TestDiskUsageContextFormatWrite(t *testing.T) {
Context: Context{
Format: NewDiskUsageFormat("table", false),
},
Verbose: false},
Verbose: false,
},
`TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 0 0 0B 0B
Containers 0 0 0B 0B
Expand Down
2 changes: 1 addition & 1 deletion cli/command/formatter/displayutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestEllipsis(t *testing.T) {
var testcases = []struct {
testcases := []struct {
source string
width int
expected string
Expand Down
1 change: 0 additions & 1 deletion cli/command/formatter/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func imageFormatTaggedAndDigest(ctx ImageContext, image types.ImageSummary) []*i
}
} else {
addImage(repo, "<none>", "")

}
}
return images
Expand Down
3 changes: 1 addition & 2 deletions cli/command/formatter/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"testing"
)

type dummy struct {
}
type dummy struct{}

func (d *dummy) Func1() string {
return "Func1"
Expand Down
1 change: 0 additions & 1 deletion cli/command/formatter/tabwriter/tabwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ func (b *Writer) Write(buf []byte) (n int, err error) {
b.startEscape(ch)
}
}

} else {
// inside escape
if ch == b.endChar {
Expand Down
1 change: 0 additions & 1 deletion cli/command/idresolver/idresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string,
default:
return "", errors.Errorf("unsupported type")
}

}

// Resolve will attempt to resolve an ID to a Name by querying the manager.
Expand Down
5 changes: 2 additions & 3 deletions cli/command/image/build/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {

func TestGetContextFromReaderString(t *testing.T) {
tarArchive, relDockerfile, err := GetContextFromReader(io.NopCloser(strings.NewReader(dockerfileContents)), "")

if err != nil {
t.Fatalf("Error when executing GetContextFromReader: %s", err)
}
Expand Down Expand Up @@ -253,7 +252,7 @@ func chdir(t *testing.T, dir string) {
}

func TestIsArchive(t *testing.T) {
var testcases = []struct {
testcases := []struct {
doc string
header []byte
expected bool
Expand Down Expand Up @@ -285,7 +284,7 @@ func TestIsArchive(t *testing.T) {
}

func TestDetectArchiveReader(t *testing.T) {
var testcases = []struct {
testcases := []struct {
file string
desc string
expected bool
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
{Name: "Dockerfile"},
{Name: "foo"},
}
var cmpTarHeaderNameAndOwner = cmp.Comparer(func(x, y tar.Header) bool {
cmpTarHeaderNameAndOwner := cmp.Comparer(func(x, y tar.Header) bool {
return x.Name == y.Name && x.Uid == y.Uid && x.Gid == y.Gid
})
assert.DeepEqual(t, expected, headers, cmpTarHeaderNameAndOwner)
Expand Down
6 changes: 4 additions & 2 deletions cli/command/image/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (cli *fakeClient) ImageSave(_ context.Context, images []string) (io.ReadClo
}

func (cli *fakeClient) ImageRemove(_ context.Context, image string,
options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
options types.ImageRemoveOptions,
) ([]types.ImageDeleteResponseItem, error) {
if cli.imageRemoveFunc != nil {
return cli.imageRemoveFunc(image, options)
}
Expand Down Expand Up @@ -101,7 +102,8 @@ func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, image string) (typ
}

func (cli *fakeClient) ImageImport(_ context.Context, source types.ImageImportSource, ref string,
options types.ImageImportOptions) (io.ReadCloser, error) {
options types.ImageImportOptions,
) (io.ReadCloser, error) {
if cli.imageImportFunc != nil {
return cli.imageImportFunc(source, ref, options)
}
Expand Down
Loading