mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6f7e8d1d7f
As is seem in the comment of `normaliseWorkdir` for windows: ``` ... // WORKDIR c:\\foo --> C:\foo // WORKDIR \\foo --> C:\foo ... ``` However, this is not the case in the current implementation because `filepath.FromSlash` is used and `FromSlash` does not replace multiple separator with a single one (`file.Clean` does). So `normaliseWorkdir` does not truly normalize workdir. This fix changes the implementation of `normaliseWorkdir` and use `filepath.Clean` instead of `filepath.FromSlash`. Additional test cases have been added to the unit test. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
// +build windows
|
|
|
|
package dockerfile
|
|
|
|
import "testing"
|
|
|
|
func TestNormaliseWorkdir(t *testing.T) {
|
|
tests := []struct{ current, requested, expected, etext string }{
|
|
{``, ``, ``, `cannot normalise nothing`},
|
|
{``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
{``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
{`c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
{`c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
{``, `a`, `C:\a`, ``},
|
|
{``, `c:\foo`, `C:\foo`, ``},
|
|
{``, `c:\\foo`, `C:\foo`, ``},
|
|
{``, `\foo`, `C:\foo`, ``},
|
|
{``, `\\foo`, `C:\foo`, ``},
|
|
{``, `/foo`, `C:\foo`, ``},
|
|
{``, `C:/foo`, `C:\foo`, ``},
|
|
{`C:\foo`, `bar`, `C:\foo\bar`, ``},
|
|
{`C:\foo`, `/bar`, `C:\bar`, ``},
|
|
{`C:\foo`, `\bar`, `C:\bar`, ``},
|
|
}
|
|
for _, i := range tests {
|
|
r, e := normaliseWorkdir(i.current, i.requested)
|
|
|
|
if i.etext != "" && e == nil {
|
|
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
|
|
}
|
|
|
|
if i.etext != "" && e.Error() != i.etext {
|
|
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
|
|
}
|
|
|
|
if r != i.expected {
|
|
t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
|
|
}
|
|
}
|
|
}
|