builder/dockerfile: 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:
parent
9d4abbbc30
commit
3e0565e17c
10 changed files with 21 additions and 27 deletions
|
@ -406,7 +406,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b
|
|||
tmpFileName = unnamedFilename
|
||||
}
|
||||
tmpFileName = filepath.Join(tmpDir, tmpFileName)
|
||||
tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
||||
tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -510,11 +510,11 @@ func copyFile(archiver *archive.Archiver, source, dest string, identity *idtools
|
|||
// modified for use on Windows to handle volume GUID paths. These paths
|
||||
// are of the form \\?\Volume{<GUID>}\<path>. An example would be:
|
||||
// \\?\Volume{dae8d3ac-b9a1-11e9-88eb-e8554b2ba1db}\bin\busybox.exe
|
||||
if err := system.MkdirAll(filepath.Dir(dest), 0755); err != nil {
|
||||
if err := system.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := idtools.MkdirAllAndChownNew(filepath.Dir(dest), 0755, *identity); err != nil {
|
||||
if err := idtools.MkdirAllAndChownNew(filepath.Dir(dest), 0o755, *identity); err != nil {
|
||||
return errors.Wrapf(err, "failed to create new directory")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestIsExistingDirectory(t *testing.T) {
|
|||
tmpdir := fs.NewDir(t, "dir-exists-test")
|
||||
defer tmpdir.Remove()
|
||||
|
||||
var testcases = []struct {
|
||||
testcases := []struct {
|
||||
doc string
|
||||
path string
|
||||
expected bool
|
||||
|
@ -47,7 +47,7 @@ func TestIsExistingDirectory(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetFilenameForDownload(t *testing.T) {
|
||||
var testcases = []struct {
|
||||
testcases := []struct {
|
||||
path string
|
||||
disposition string
|
||||
expected string
|
||||
|
|
|
@ -430,7 +430,8 @@ func TestPrependEnvOnCmd(t *testing.T) {
|
|||
cmd := []string{"foo", "bar"}
|
||||
cmdWithEnv := prependEnvOnCmd(buildArgs, args, cmd)
|
||||
expected := strslice.StrSlice([]string{
|
||||
"|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar"})
|
||||
"|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar",
|
||||
})
|
||||
assert.Check(t, is.DeepEqual(expected, cmdWithEnv))
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,6 @@ func normalizeWorkdirWindows(current string, requested string) (string, error) {
|
|||
//
|
||||
// The commands when this function is called are RUN, ENTRYPOINT and CMD.
|
||||
func resolveCmdLine(cmd instructions.ShellDependantCmdLine, runConfig *container.Config, os, command, original string) ([]string, bool) {
|
||||
|
||||
// Make sure we return an empty array if there is no cmd.CmdLine
|
||||
if len(cmd.CmdLine) == 0 {
|
||||
return []string{}, runConfig.ArgsEscaped
|
||||
|
|
|
@ -104,11 +104,10 @@ func TestDispatch(t *testing.T) {
|
|||
defer cleanup()
|
||||
|
||||
for filename, content := range tc.files {
|
||||
createTestTempFile(t, contextDir, filename, content, 0777)
|
||||
createTestTempFile(t, contextDir, filename, content, 0o777)
|
||||
}
|
||||
|
||||
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error when creating tar stream: %s", err)
|
||||
}
|
||||
|
@ -120,7 +119,6 @@ func TestDispatch(t *testing.T) {
|
|||
}()
|
||||
|
||||
buildContext, err := remotecontext.FromArchive(tarStream)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error when creating tar context: %s", err)
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ othergrp:x:6666:
|
|||
contextDir, cleanup := createTestTempDir(t, "", "builder-chown-parse-test")
|
||||
defer cleanup()
|
||||
|
||||
if err := os.Mkdir(filepath.Join(contextDir, "etc"), 0755); err != nil {
|
||||
if err := os.Mkdir(filepath.Join(contextDir, "etc"), 0o755); err != nil {
|
||||
t.Fatalf("error creating test directory: %v", err)
|
||||
}
|
||||
|
||||
for filename, content := range testFiles {
|
||||
createTestTempFile(t, filepath.Join(contextDir, "etc"), filename, content, 0644)
|
||||
createTestTempFile(t, filepath.Join(contextDir, "etc"), filename, content, 0o644)
|
||||
}
|
||||
|
||||
// positive tests
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestEmptyDockerfile(t *testing.T) {
|
|||
contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test")
|
||||
defer cleanup()
|
||||
|
||||
createTestTempFile(t, contextDir, builder.DefaultDockerfileName, "", 0777)
|
||||
createTestTempFile(t, contextDir, builder.DefaultDockerfileName, "", 0o777)
|
||||
|
||||
readAndCheckDockerfile(t, "emptyDockerfile", contextDir, "", "the Dockerfile (Dockerfile) cannot be empty")
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func TestCopyRunConfig(t *testing.T) {
|
|||
defaultEnv := []string{"foo=1"}
|
||||
defaultCmd := []string{"old"}
|
||||
|
||||
var testcases = []struct {
|
||||
testcases := []struct {
|
||||
doc string
|
||||
modifiers []runConfigModifier
|
||||
expected *container.Config
|
||||
|
|
|
@ -45,7 +45,6 @@ func getAccountIdentity(ctx context.Context, builder *Builder, accountName strin
|
|||
// Check if the account name is one unique to containers.
|
||||
if strings.EqualFold(accountName, "ContainerAdministrator") {
|
||||
return idtools.Identity{SID: idtools.ContainerAdministratorSidString}, nil
|
||||
|
||||
} else if strings.EqualFold(accountName, "ContainerUser") {
|
||||
return idtools.Identity{SID: idtools.ContainerUserSidString}, nil
|
||||
}
|
||||
|
@ -56,7 +55,6 @@ func getAccountIdentity(ctx context.Context, builder *Builder, accountName strin
|
|||
}
|
||||
|
||||
func lookupNTAccount(ctx context.Context, builder *Builder, accountName string, state *dispatchState) (idtools.Identity, error) {
|
||||
|
||||
source, _ := filepath.Split(os.Args[0])
|
||||
|
||||
target := "C:\\Docker"
|
||||
|
@ -72,14 +70,15 @@ func lookupNTAccount(ctx context.Context, builder *Builder, accountName string,
|
|||
|
||||
runConfig.Cmd = []string{targetExecutable, "getaccountsid", accountName}
|
||||
|
||||
hostConfig := &container.HostConfig{Mounts: []mount.Mount{
|
||||
{
|
||||
Type: mount.TypeBind,
|
||||
Source: source,
|
||||
Target: target,
|
||||
ReadOnly: true,
|
||||
hostConfig := &container.HostConfig{
|
||||
Mounts: []mount.Mount{
|
||||
{
|
||||
Type: mount.TypeBind,
|
||||
Source: source,
|
||||
Target: target,
|
||||
ReadOnly: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
container, err := builder.containerManager.Create(ctx, runConfig, hostConfig)
|
||||
|
|
|
@ -136,8 +136,7 @@ func (l *mockLayer) DiffID() layer.DiffID {
|
|||
return "abcdef"
|
||||
}
|
||||
|
||||
type mockRWLayer struct {
|
||||
}
|
||||
type mockRWLayer struct{}
|
||||
|
||||
func (l *mockRWLayer) Release() error {
|
||||
return nil
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
// When an error occurs, it terminates the test.
|
||||
func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
|
||||
path, err := os.MkdirTemp(dir, prefix)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error when creating directory %s with prefix %s: %s", dir, prefix, err)
|
||||
}
|
||||
|
@ -30,7 +29,6 @@ func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
|
|||
func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string {
|
||||
filePath := filepath.Join(dir, filename)
|
||||
err := os.WriteFile(filePath, []byte(contents), perm)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error when creating %s file: %s", filename, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue