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 go with gofumpt (with -lang=1.19) #3828

Merged
merged 1 commit into from
Nov 4, 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
8 changes: 4 additions & 4 deletions cli-plugins/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func TestGetPlugin(t *testing.T) {
dir := fs.NewDir(t, t.Name(),
fs.WithFile("docker-bbb", `
#!/bin/sh
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
fs.WithFile("docker-aaa", `
#!/bin/sh
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
)
defer dir.Remove()

Expand All @@ -109,10 +109,10 @@ func TestListPluginsIsSorted(t *testing.T) {
dir := fs.NewDir(t, t.Name(),
fs.WithFile("docker-bbb", `
#!/bin/sh
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
fs.WithFile("docker-aaa", `
#!/bin/sh
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
)
defer dir.Remove()

Expand Down
2 changes: 1 addition & 1 deletion cli/command/context/export-import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestExportExistingFile(t *testing.T) {
contextFile := filepath.Join(t.TempDir(), "exported")
cli := makeFakeCli(t)
cli.ErrBuffer().Reset()
assert.NilError(t, os.WriteFile(contextFile, []byte{}, 0644))
assert.NilError(t, os.WriteFile(contextFile, []byte{}, 0o644))
err := RunExport(cli, &ExportOptions{ContextName: "test", Dest: contextFile})
assert.Assert(t, os.IsExist(err))
}
2 changes: 1 addition & 1 deletion cli/command/context/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func writeTo(dockerCli command.Cli, reader io.Reader, dest string) error {
}
writer = dockerCli.Out()
} else {
f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
if imageID == "" {
return errors.Errorf("Server did not provide an image ID. Cannot write %s", options.imageIDFile)
}
if err := os.WriteFile(options.imageIDFile, []byte(imageID), 0666); err != nil {
if err := os.WriteFile(options.imageIDFile, []byte(imageID), 0o666); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/image/build/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl
randomName: func(_ string, _ *tar.Header, _ io.Reader) (*tar.Header, []byte, error) {
header := &tar.Header{
Name: randomName,
Mode: 0600,
Mode: 0o600,
ModTime: now,
Typeflag: tar.TypeReg,
AccessTime: now,
Expand All @@ -397,7 +397,7 @@ func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl
if h == nil {
h = &tar.Header{
Name: ".dockerignore",
Mode: 0600,
Mode: 0o600,
ModTime: now,
Typeflag: tar.TypeReg,
AccessTime: now,
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/build/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func createTestTempDir(t *testing.T) string {
func createTestTempFile(t *testing.T, dir, filename, contents string) string {
t.Helper()
filePath := filepath.Join(dir, filename)
err := os.WriteFile(filePath, []byte(contents), 0777)
err := os.WriteFile(filePath, []byte(contents), 0o777)
assert.NilError(t, err)
return filePath
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/image/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
t.Setenv("DOCKER_BUILDKIT", "0")

buildDir := filepath.Join(t.TempDir(), "github.com", "docker", "no-such-repository")
err := os.MkdirAll(buildDir, 0777)
err := os.MkdirAll(buildDir, 0o777)
assert.NilError(t, err)
err = os.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644)
err = os.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0o644)
assert.NilError(t, err)

client := test.NewFakeCli(&fakeClient{})
Expand Down
4 changes: 2 additions & 2 deletions cli/command/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestSetConfigsWithCredSpecAndConfigs(t *testing.T) {
// these are the default field values
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
}), "expected configRefs to contain bar config")
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestSetConfigsOnlyConfigs(t *testing.T) {
// these are the default field values
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
}))
}
Expand Down
6 changes: 3 additions & 3 deletions cli/command/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ func TestUpdateGetUpdatedConfigs(t *testing.T) {
Name: "foo",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
"barRef": {
Expand All @@ -1076,7 +1076,7 @@ func TestUpdateGetUpdatedConfigs(t *testing.T) {
Name: "bar",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
"bazRef": {
Expand All @@ -1086,7 +1086,7 @@ func TestUpdateGetUpdatedConfigs(t *testing.T) {
Name: "baz",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
"credRef": {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/trust/key_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

const (
nonOwnerReadWriteMask = 0077
nonOwnerReadWriteMask = 0o077
)

type keyLoadOptions struct {
Expand Down
10 changes: 5 additions & 5 deletions cli/command/trust/key_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,35 +175,35 @@ func TestLoadKeyTooPermissive(t *testing.T) {
func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
privKeyDir := t.TempDir()
privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem")
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0477))
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0o477))

// import the key to our keyStorageDir
_, err := getPrivKeyBytesFromPath(privKeyFilepath)
expected := fmt.Sprintf("private key file %s must not be readable or writable by others", privKeyFilepath)
assert.Error(t, err, expected)

privKeyFilepath = filepath.Join(privKeyDir, "privkey667.pem")
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0677))
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0o677))

_, err = getPrivKeyBytesFromPath(privKeyFilepath)
expected = fmt.Sprintf("private key file %s must not be readable or writable by others", privKeyFilepath)
assert.Error(t, err, expected)

privKeyFilepath = filepath.Join(privKeyDir, "privkey777.pem")
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0777))
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0o777))

_, err = getPrivKeyBytesFromPath(privKeyFilepath)
expected = fmt.Sprintf("private key file %s must not be readable or writable by others", privKeyFilepath)
assert.Error(t, err, expected)

privKeyFilepath = filepath.Join(privKeyDir, "privkey400.pem")
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0400))
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0o400))

_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.NilError(t, err)

privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem")
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0600))
assert.NilError(t, os.WriteFile(privKeyFilepath, privKeyFixture, 0o600))

_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.NilError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/trust/signer_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func ingestPublicKeys(pubKeyPaths []string) ([]data.PublicKey, error) {
pubKeys := []data.PublicKey{}
for _, pubKeyPath := range pubKeyPaths {
// Read public key bytes from PEM file, limit to 1 KiB
pubKeyFile, err := os.OpenFile(pubKeyPath, os.O_RDONLY, 0666)
pubKeyFile, err := os.OpenFile(pubKeyPath, os.O_RDONLY, 0o666)
if err != nil {
return nil, errors.Wrap(err, "unable to read public key from file")
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestValidateOutputPath(t *testing.T) {
basedir := t.TempDir()
dir := filepath.Join(basedir, "dir")
notexist := filepath.Join(basedir, "notexist")
err := os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0o755)
assert.NilError(t, err)
file := filepath.Join(dir, "file")
err = os.WriteFile(file, []byte("hi"), 0644)
err = os.WriteFile(file, []byte("hi"), 0o644)
assert.NilError(t, err)
testcases := []struct {
path string
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func convertFileObject(
}
mode := config.Mode
if mode == nil {
mode = uint32Ptr(0444)
mode = uint32Ptr(0o444)
}

return swarmReferenceObject{
Expand Down
14 changes: 7 additions & 7 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestConvertFileObject(t *testing.T) {
Target: "target",
UID: "user",
GID: "group",
Mode: uint32Ptr(0644),
Mode: uint32Ptr(0o644),
}
swarmRef, err := convertFileObject(namespace, config, lookupConfig)
assert.NilError(t, err)
Expand All @@ -438,7 +438,7 @@ func TestConvertFileObject(t *testing.T) {
Name: config.Target,
UID: config.UID,
GID: config.GID,
Mode: os.FileMode(0644),
Mode: os.FileMode(0o644),
},
}
assert.Check(t, is.DeepEqual(expected, swarmRef))
Expand All @@ -463,7 +463,7 @@ func TestConvertFileObjectDefaults(t *testing.T) {
Name: config.Source,
UID: "0",
GID: "0",
Mode: os.FileMode(0444),
Mode: os.FileMode(0o444),
},
}
assert.Check(t, is.DeepEqual(expected, swarmRef))
Expand Down Expand Up @@ -511,7 +511,7 @@ func TestConvertServiceSecrets(t *testing.T) {
Name: "bar_secret",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
{
Expand All @@ -520,7 +520,7 @@ func TestConvertServiceSecrets(t *testing.T) {
Name: "foo_secret",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
}
Expand Down Expand Up @@ -570,7 +570,7 @@ func TestConvertServiceConfigs(t *testing.T) {
Name: "bar_config",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
{
Expand All @@ -583,7 +583,7 @@ func TestConvertServiceConfigs(t *testing.T) {
Name: "foo_config",
UID: "0",
GID: "0",
Mode: 0444,
Mode: 0o444,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions cli/compose/loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
Target: "/my_config",
UID: "103",
GID: "103",
Mode: uint32Ptr(0440),
Mode: uint32Ptr(0o440),
},
},
ContainerName: "my-web-container",
Expand Down Expand Up @@ -342,7 +342,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
Target: "my_secret",
UID: "103",
GID: "103",
Mode: uint32Ptr(0440),
Mode: uint32Ptr(0o440),
},
},
SecurityOpt: []string{
Expand Down
18 changes: 9 additions & 9 deletions cli/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestEmptyFile(t *testing.T) {
tmpHome := t.TempDir()

fn := filepath.Join(tmpHome, ConfigFileName)
err := os.WriteFile(fn, []byte(""), 0600)
err := os.WriteFile(fn, []byte(""), 0o600)
assert.NilError(t, err)

_, err = Load(tmpHome)
Expand All @@ -83,7 +83,7 @@ func TestEmptyJSON(t *testing.T) {
tmpHome := t.TempDir()

fn := filepath.Join(tmpHome, ConfigFileName)
err := os.WriteFile(fn, []byte("{}"), 0600)
err := os.WriteFile(fn, []byte("{}"), 0o600)
assert.NilError(t, err)

config, err := Load(tmpHome)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestNewJSON(t *testing.T) {

fn := filepath.Join(tmpHome, ConfigFileName)
js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }`
if err := os.WriteFile(fn, []byte(js), 0600); err != nil {
if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func TestNewJSONNoEmail(t *testing.T) {

fn := filepath.Join(tmpHome, ConfigFileName)
js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }`
if err := os.WriteFile(fn, []byte(js), 0600); err != nil {
if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func TestJSONWithPsFormat(t *testing.T) {
"auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected]" } },
"psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
}`
if err := os.WriteFile(fn, []byte(js), 0600); err != nil {
if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
t.Fatal(err)
}

Expand All @@ -210,7 +210,7 @@ func TestJSONWithCredentialStore(t *testing.T) {
"auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected]" } },
"credsStore": "crazy-secure-storage"
}`
if err := os.WriteFile(fn, []byte(js), 0600); err != nil {
if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
t.Fatal(err)
}

Expand All @@ -237,7 +237,7 @@ func TestJSONWithCredentialHelpers(t *testing.T) {
"auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected]" } },
"credHelpers": { "images.io": "images-io", "containers.com": "crazy-secure-storage" }
}`
if err := os.WriteFile(fn, []byte(js), 0600); err != nil {
if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -325,7 +325,7 @@ func TestJSONSaveWithNoFile(t *testing.T) {
tmpHome := t.TempDir()

fn := filepath.Join(tmpHome, ConfigFileName)
f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
defer f.Close()

assert.NilError(t, config.SaveToWriter(f))
Expand All @@ -350,7 +350,7 @@ func TestLoadDefaultConfigFile(t *testing.T) {

filename := filepath.Join(dir, ConfigFileName)
content := []byte(`{"PsFormat": "format"}`)
err := os.WriteFile(filename, content, 0644)
err := os.WriteFile(filename, content, 0o644)
assert.NilError(t, err)

configFile := LoadDefaultConfigFile(buffer)
Expand Down
2 changes: 1 addition & 1 deletion cli/config/configfile/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
}

dir := filepath.Dir(configFile.Filename)
if err := os.MkdirAll(dir, 0700); err != nil {
if err := os.MkdirAll(dir, 0o700); err != nil {
return err
}
temp, err := os.CreateTemp(dir, filepath.Base(configFile.Filename))
Expand Down
2 changes: 1 addition & 1 deletion cli/config/configfile/file_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// ignoring any error during the process.
func copyFilePermissions(src, dst string) {
var (
mode os.FileMode = 0600
mode os.FileMode = 0o600
uid, gid int
)

Expand Down
Loading