Skip to content

Commit ae8dbea

Browse files
committed
*: normalize the use of normalize
Signed-off-by: Stephen J Day <stephen.day@docker.com>
1 parent f291c95 commit ae8dbea

13 files changed

+45
-45
lines changed

builder/dockerfile/dispatchers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func workdir(req dispatchRequest) error {
387387
runConfig := req.state.runConfig
388388
// This is from the Dockerfile and will not necessarily be in platform
389389
// specific semantics, hence ensure it is converted.
390-
runConfig.WorkingDir, err = normaliseWorkdir(req.builder.platform, runConfig.WorkingDir, req.args[0])
390+
runConfig.WorkingDir, err = normalizeWorkdir(req.builder.platform, runConfig.WorkingDir, req.args[0])
391391
if err != nil {
392392
return err
393393
}

builder/dockerfile/dispatchers_unix.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"path/filepath"
1010
)
1111

12-
// normaliseWorkdir normalises a user requested working directory in a
12+
// normalizeWorkdir normalizes a user requested working directory in a
1313
// platform semantically consistent way.
14-
func normaliseWorkdir(_ string, current string, requested string) (string, error) {
14+
func normalizeWorkdir(_ string, current string, requested string) (string, error) {
1515
if requested == "" {
16-
return "", errors.New("cannot normalise nothing")
16+
return "", errors.New("cannot normalize nothing")
1717
}
1818
current = filepath.FromSlash(current)
1919
requested = filepath.FromSlash(requested)

builder/dockerfile/dispatchers_unix_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ import (
77
"testing"
88
)
99

10-
func TestNormaliseWorkdir(t *testing.T) {
10+
func TestNormalizeWorkdir(t *testing.T) {
1111
testCases := []struct{ current, requested, expected, expectedError string }{
12-
{``, ``, ``, `cannot normalise nothing`},
12+
{``, ``, ``, `cannot normalize nothing`},
1313
{``, `foo`, `/foo`, ``},
1414
{``, `/foo`, `/foo`, ``},
1515
{`/foo`, `bar`, `/foo/bar`, ``},
1616
{`/foo`, `/bar`, `/bar`, ``},
1717
}
1818

1919
for _, test := range testCases {
20-
normalised, err := normaliseWorkdir(runtime.GOOS, test.current, test.requested)
20+
normalized, err := normalizeWorkdir(runtime.GOOS, test.current, test.requested)
2121

2222
if test.expectedError != "" && err == nil {
23-
t.Fatalf("NormaliseWorkdir should return an error %s, got nil", test.expectedError)
23+
t.Fatalf("NormalizeWorkdir should return an error %s, got nil", test.expectedError)
2424
}
2525

2626
if test.expectedError != "" && err.Error() != test.expectedError {
27-
t.Fatalf("NormaliseWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
27+
t.Fatalf("NormalizeWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
2828
}
2929

30-
if normalised != test.expected {
31-
t.Fatalf("NormaliseWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalised)
30+
if normalized != test.expected {
31+
t.Fatalf("NormalizeWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalized)
3232
}
3333
}
3434
}

builder/dockerfile/dispatchers_windows.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ import (
1414

1515
var pattern = regexp.MustCompile(`^[a-zA-Z]:\.$`)
1616

17-
// normaliseWorkdir normalises a user requested working directory in a
17+
// normalizeWorkdir normalizes a user requested working directory in a
1818
// platform semantically consistent way.
19-
func normaliseWorkdir(platform string, current string, requested string) (string, error) {
19+
func normalizeWorkdir(platform string, current string, requested string) (string, error) {
2020
if platform == "" {
2121
platform = "windows"
2222
}
2323
if platform == "windows" {
24-
return normaliseWorkdirWindows(current, requested)
24+
return normalizeWorkdirWindows(current, requested)
2525
}
26-
return normaliseWorkdirUnix(current, requested)
26+
return normalizeWorkdirUnix(current, requested)
2727
}
2828

29-
// normaliseWorkdirUnix normalises a user requested working directory in a
29+
// normalizeWorkdirUnix normalizes a user requested working directory in a
3030
// platform semantically consistent way.
31-
func normaliseWorkdirUnix(current string, requested string) (string, error) {
31+
func normalizeWorkdirUnix(current string, requested string) (string, error) {
3232
if requested == "" {
33-
return "", errors.New("cannot normalise nothing")
33+
return "", errors.New("cannot normalize nothing")
3434
}
3535
current = strings.Replace(current, string(os.PathSeparator), "/", -1)
3636
requested = strings.Replace(requested, string(os.PathSeparator), "/", -1)
@@ -40,11 +40,11 @@ func normaliseWorkdirUnix(current string, requested string) (string, error) {
4040
return requested, nil
4141
}
4242

43-
// normaliseWorkdirWindows normalises a user requested working directory in a
43+
// normalizeWorkdirWindows normalizes a user requested working directory in a
4444
// platform semantically consistent way.
45-
func normaliseWorkdirWindows(current string, requested string) (string, error) {
45+
func normalizeWorkdirWindows(current string, requested string) (string, error) {
4646
if requested == "" {
47-
return "", errors.New("cannot normalise nothing")
47+
return "", errors.New("cannot normalize nothing")
4848
}
4949

5050
// `filepath.Clean` will replace "" with "." so skip in that case

builder/dockerfile/dispatchers_windows_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package dockerfile
44

55
import "testing"
66

7-
func TestNormaliseWorkdir(t *testing.T) {
7+
func TestNormalizeWorkdir(t *testing.T) {
88
tests := []struct{ platform, current, requested, expected, etext string }{
9-
{"windows", ``, ``, ``, `cannot normalise nothing`},
9+
{"windows", ``, ``, ``, `cannot normalize nothing`},
1010
{"windows", ``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
1111
{"windows", ``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
1212
{"windows", `c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
@@ -21,26 +21,26 @@ func TestNormaliseWorkdir(t *testing.T) {
2121
{"windows", `C:\foo`, `bar`, `C:\foo\bar`, ``},
2222
{"windows", `C:\foo`, `/bar`, `C:\bar`, ``},
2323
{"windows", `C:\foo`, `\bar`, `C:\bar`, ``},
24-
{"linux", ``, ``, ``, `cannot normalise nothing`},
24+
{"linux", ``, ``, ``, `cannot normalize nothing`},
2525
{"linux", ``, `foo`, `/foo`, ``},
2626
{"linux", ``, `/foo`, `/foo`, ``},
2727
{"linux", `/foo`, `bar`, `/foo/bar`, ``},
2828
{"linux", `/foo`, `/bar`, `/bar`, ``},
2929
{"linux", `\a`, `b\c`, `/a/b/c`, ``},
3030
}
3131
for _, i := range tests {
32-
r, e := normaliseWorkdir(i.platform, i.current, i.requested)
32+
r, e := normalizeWorkdir(i.platform, i.current, i.requested)
3333

3434
if i.etext != "" && e == nil {
35-
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
35+
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
3636
}
3737

3838
if i.etext != "" && e.Error() != i.etext {
39-
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
39+
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
4040
}
4141

4242
if r != i.expected {
43-
t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
43+
t.Fatalf("TestNormalizeWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
4444
}
4545
}
4646
}

builder/dockerfile/internals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (b *Builder) performCopy(state *dispatchState, inst copyInstruction) error
140140
func createDestInfo(workingDir string, inst copyInstruction, imageMount *imageMount) (copyInfo, error) {
141141
// Twiddle the destination when it's a relative path - meaning, make it
142142
// relative to the WORKINGDIR
143-
dest, err := normaliseDest(workingDir, inst.dest)
143+
dest, err := normalizeDest(workingDir, inst.dest)
144144
if err != nil {
145145
return copyInfo{}, errors.Wrapf(err, "invalid %s", inst.cmdName)
146146
}

builder/dockerfile/internals_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/docker/docker/pkg/system"
1111
)
1212

13-
// normaliseDest normalises the destination of a COPY/ADD command in a
13+
// normalizeDest normalizes the destination of a COPY/ADD command in a
1414
// platform semantically consistent way.
15-
func normaliseDest(workingDir, requested string) (string, error) {
15+
func normalizeDest(workingDir, requested string) (string, error) {
1616
dest := filepath.FromSlash(requested)
1717
endsInSlash := strings.HasSuffix(requested, string(os.PathSeparator))
1818
if !system.IsAbs(requested) {

builder/dockerfile/internals_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/pkg/errors"
1111
)
1212

13-
// normaliseDest normalises the destination of a COPY/ADD command in a
13+
// normalizeDest normalizes the destination of a COPY/ADD command in a
1414
// platform semantically consistent way.
15-
func normaliseDest(workingDir, requested string) (string, error) {
15+
func normalizeDest(workingDir, requested string) (string, error) {
1616
dest := filepath.FromSlash(requested)
1717
endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator))
1818

builder/dockerfile/internals_windows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func TestNormaliseDest(t *testing.T) {
13+
func TestNormalizeDest(t *testing.T) {
1414
tests := []struct{ current, requested, expected, etext string }{
1515
{``, `D:\`, ``, `Windows does not support destinations not on the system drive (C:)`},
1616
{``, `e:/`, ``, `Windows does not support destinations not on the system drive (C:)`},
@@ -40,7 +40,7 @@ func TestNormaliseDest(t *testing.T) {
4040
}
4141
for _, testcase := range tests {
4242
msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
43-
actual, err := normaliseDest(testcase.current, testcase.requested)
43+
actual, err := normalizeDest(testcase.current, testcase.requested)
4444
if testcase.etext == "" {
4545
if !assert.NoError(t, err, msg) {
4646
continue

integration-cli/docker_cli_commit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
122122
imageID = strings.TrimSpace(imageID)
123123

124124
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
125-
prefix = strings.ToUpper(prefix) // Force C: as that's how WORKDIR is normalised on Windows
125+
prefix = strings.ToUpper(prefix) // Force C: as that's how WORKDIR is normalized on Windows
126126
expected := map[string]string{
127127
"Config.ExposedPorts": "map[8080/tcp:{}]",
128128
"Config.Env": "[DEBUG=true test=1 PATH=/foo]",

0 commit comments

Comments
 (0)