testutil: format code with gofumpt

Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-01-20 13:42:50 +01:00
parent 4c281fb29a
commit a31411c679
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
7 changed files with 21 additions and 22 deletions

View file

@ -99,7 +99,7 @@ type Daemon struct {
func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) { func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
storageDriver := os.Getenv("DOCKER_GRAPHDRIVER") storageDriver := os.Getenv("DOCKER_GRAPHDRIVER")
if err := os.MkdirAll(SockRoot, 0700); err != nil { if err := os.MkdirAll(SockRoot, 0o700); err != nil {
return nil, errors.Wrapf(err, "failed to create daemon socket root %q", SockRoot) return nil, errors.Wrapf(err, "failed to create daemon socket root %q", SockRoot)
} }
@ -110,7 +110,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
return nil, err return nil, err
} }
daemonRoot := filepath.Join(daemonFolder, "root") daemonRoot := filepath.Join(daemonFolder, "root")
if err := os.MkdirAll(daemonRoot, 0755); err != nil { if err := os.MkdirAll(daemonRoot, 0o755); err != nil {
return nil, errors.Wrapf(err, "failed to create daemon root %q", daemonRoot) return nil, errors.Wrapf(err, "failed to create daemon root %q", daemonRoot)
} }
@ -140,7 +140,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
} }
if d.rootlessUser != nil { if d.rootlessUser != nil {
if err := os.Chmod(SockRoot, 0777); err != nil { if err := os.Chmod(SockRoot, 0o777); err != nil {
return nil, err return nil, err
} }
uid, err := strconv.Atoi(d.rootlessUser.Uid) uid, err := strconv.Atoi(d.rootlessUser.Uid)
@ -157,20 +157,20 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
if err := os.Chown(d.Root, uid, gid); err != nil { if err := os.Chown(d.Root, uid, gid); err != nil {
return nil, err return nil, err
} }
if err := os.MkdirAll(filepath.Dir(d.execRoot), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(d.execRoot), 0o700); err != nil {
return nil, err return nil, err
} }
if err := os.Chown(filepath.Dir(d.execRoot), uid, gid); err != nil { if err := os.Chown(filepath.Dir(d.execRoot), uid, gid); err != nil {
return nil, err return nil, err
} }
if err := os.MkdirAll(d.execRoot, 0700); err != nil { if err := os.MkdirAll(d.execRoot, 0o700); err != nil {
return nil, err return nil, err
} }
if err := os.Chown(d.execRoot, uid, gid); err != nil { if err := os.Chown(d.execRoot, uid, gid); err != nil {
return nil, err return nil, err
} }
d.rootlessXDGRuntimeDir = filepath.Join(d.Folder, "xdgrun") d.rootlessXDGRuntimeDir = filepath.Join(d.Folder, "xdgrun")
if err := os.MkdirAll(d.rootlessXDGRuntimeDir, 0700); err != nil { if err := os.MkdirAll(d.rootlessXDGRuntimeDir, 0o700); err != nil {
return nil, err return nil, err
} }
if err := os.Chown(d.rootlessXDGRuntimeDir, uid, gid); err != nil { if err := os.Chown(d.rootlessXDGRuntimeDir, uid, gid); err != nil {
@ -308,7 +308,7 @@ func (d *Daemon) Start(t testing.TB, args ...string) {
// StartWithError starts the daemon and return once it is ready to receive requests. // StartWithError starts the daemon and return once it is ready to receive requests.
// It returns an error in case it couldn't start. // It returns an error in case it couldn't start.
func (d *Daemon) StartWithError(args ...string) error { func (d *Daemon) StartWithError(args ...string) error {
logFile, err := os.OpenFile(filepath.Join(d.Folder, "docker.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) logFile, err := os.OpenFile(filepath.Join(d.Folder, "docker.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
if err != nil { if err != nil {
return errors.Wrapf(err, "[%s] failed to create logfile", d.id) return errors.Wrapf(err, "[%s] failed to create logfile", d.id)
} }

View file

@ -16,9 +16,7 @@ const (
defaultSwarmListenAddr = "0.0.0.0" defaultSwarmListenAddr = "0.0.0.0"
) )
var ( var startArgs = []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
startArgs = []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
)
// StartNode (re)starts the daemon // StartNode (re)starts the daemon
func (d *Daemon) StartNode(t testing.TB) { func (d *Daemon) StartNode(t testing.TB) {

View file

@ -34,7 +34,7 @@ func newDir(fake *Fake) error {
if err != nil { if err != nil {
return err return err
} }
if err := os.Chmod(tmp, 0755); err != nil { if err := os.Chmod(tmp, 0o755); err != nil {
return err return err
} }
fake.Dir = tmp fake.Dir = tmp
@ -91,11 +91,11 @@ func (f *Fake) addFile(file string, content []byte) error {
fp := filepath.Join(f.Dir, filepath.FromSlash(file)) fp := filepath.Join(f.Dir, filepath.FromSlash(file))
dirpath := filepath.Dir(fp) dirpath := filepath.Dir(fp)
if dirpath != "." { if dirpath != "." {
if err := os.MkdirAll(dirpath, 0755); err != nil { if err := os.MkdirAll(dirpath, 0o755); err != nil {
return err return err
} }
} }
return os.WriteFile(fp, content, 0644) return os.WriteFile(fp, content, 0o644)
} }
// Delete a file at a path // Delete a file at a path

View file

@ -97,7 +97,8 @@ type remoteFileServer struct {
func (f *remoteFileServer) URL() string { func (f *remoteFileServer) URL() string {
u := url.URL{ u := url.URL{
Scheme: "http", Scheme: "http",
Host: f.host} Host: f.host,
}
return u.String() return u.String()
} }

View file

@ -14,7 +14,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if err := os.MkdirAll(p, 0755); err != nil { if err := os.MkdirAll(p, 0o755); err != nil {
panic(err) panic(err)
} }
l, err := net.Listen("unix", filepath.Join(p, "basic.sock")) l, err := net.Listen("unix", filepath.Join(p, "basic.sock"))

View file

@ -86,7 +86,7 @@ func CreateInRegistry(ctx context.Context, repo string, auth *registry.AuthConfi
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
inPath := filepath.Join(tmpDir, "plugin") inPath := filepath.Join(tmpDir, "plugin")
if err := os.MkdirAll(inPath, 0755); err != nil { if err := os.MkdirAll(inPath, 0o755); err != nil {
return errors.Wrap(err, "error creating plugin root") return errors.Wrap(err, "error creating plugin root")
} }
@ -163,10 +163,10 @@ func makePluginBundle(inPath string, opts ...CreateOpt) (io.ReadCloser, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := os.WriteFile(filepath.Join(inPath, "config.json"), configJSON, 0644); err != nil { if err := os.WriteFile(filepath.Join(inPath, "config.json"), configJSON, 0o644); err != nil {
return nil, err return nil, err
} }
if err := os.MkdirAll(filepath.Join(inPath, "rootfs", filepath.Dir(p.Entrypoint[0])), 0755); err != nil { if err := os.MkdirAll(filepath.Join(inPath, "rootfs", filepath.Dir(p.Entrypoint[0])), 0o755); err != nil {
return nil, errors.Wrap(err, "error creating plugin rootfs dir") return nil, errors.Wrap(err, "error creating plugin rootfs dir")
} }
@ -181,7 +181,7 @@ func makePluginBundle(inPath string, opts ...CreateOpt) (io.ReadCloser, error) {
} }
if stat == nil || stat.IsDir() { if stat == nil || stat.IsDir() {
var mode os.FileMode = 0755 var mode os.FileMode = 0o755
if stat != nil { if stat != nil {
mode = stat.Mode() mode = stat.Mode()
} }
@ -189,7 +189,7 @@ func makePluginBundle(inPath string, opts ...CreateOpt) (io.ReadCloser, error) {
return nil, errors.Wrap(err, "error preparing plugin mount destination path") return nil, errors.Wrap(err, "error preparing plugin mount destination path")
} }
} else { } else {
if err := os.MkdirAll(filepath.Join(inPath, "rootfs", filepath.Dir(m.Destination)), 0755); err != nil { if err := os.MkdirAll(filepath.Join(inPath, "rootfs", filepath.Dir(m.Destination)), 0o755); err != nil {
return nil, errors.Wrap(err, "error preparing plugin mount destination dir") return nil, errors.Wrap(err, "error preparing plugin mount destination dir")
} }
f, err := os.Create(filepath.Join(inPath, "rootfs", m.Destination)) f, err := os.Create(filepath.Join(inPath, "rootfs", m.Destination))

View file

@ -78,7 +78,7 @@ http:
username = "testuser" username = "testuser"
password = "testpassword" password = "testpassword"
email = "test@test.org" email = "test@test.org"
err := os.WriteFile(htpasswdPath, []byte(userpasswd), os.FileMode(0644)) err := os.WriteFile(htpasswdPath, []byte(userpasswd), os.FileMode(0o644))
assert.NilError(t, err) assert.NilError(t, err)
authTemplate = fmt.Sprintf(`auth: authTemplate = fmt.Sprintf(`auth:
htpasswd: htpasswd:
@ -190,7 +190,7 @@ func (r *V2) ReadBlobContents(t testing.TB, blobDigest digest.Digest) []byte {
// WriteBlobContents write the file corresponding to the specified digest with the given content // WriteBlobContents write the file corresponding to the specified digest with the given content
func (r *V2) WriteBlobContents(t testing.TB, blobDigest digest.Digest, data []byte) { func (r *V2) WriteBlobContents(t testing.TB, blobDigest digest.Digest, data []byte) {
t.Helper() t.Helper()
err := os.WriteFile(r.getBlobFilename(blobDigest), data, os.FileMode(0644)) err := os.WriteFile(r.getBlobFilename(blobDigest), data, os.FileMode(0o644))
assert.NilError(t, err, "unable to write malicious data blob") assert.NilError(t, err, "unable to write malicious data blob")
} }