2021-08-23 09:14:53 -04:00
|
|
|
//go:build windows
|
2016-05-02 21:33:59 -04:00
|
|
|
// +build windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2016-05-02 21:33:59 -04:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2017-08-22 18:25:31 -04:00
|
|
|
func TestNormalizeWorkdir(t *testing.T) {
|
2017-08-04 14:39:23 -04:00
|
|
|
tests := []struct{ platform, current, requested, expected, etext string }{
|
2017-08-22 18:25:31 -04:00
|
|
|
{"windows", ``, ``, ``, `cannot normalize nothing`},
|
2017-08-04 14:39:23 -04:00
|
|
|
{"windows", ``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
|
|
{"windows", ``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
|
|
{"windows", `c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
|
|
{"windows", `c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
|
|
|
|
{"windows", ``, `a`, `C:\a`, ``},
|
|
|
|
{"windows", ``, `c:\foo`, `C:\foo`, ``},
|
|
|
|
{"windows", ``, `c:\\foo`, `C:\foo`, ``},
|
|
|
|
{"windows", ``, `\foo`, `C:\foo`, ``},
|
|
|
|
{"windows", ``, `\\foo`, `C:\foo`, ``},
|
|
|
|
{"windows", ``, `/foo`, `C:\foo`, ``},
|
|
|
|
{"windows", ``, `C:/foo`, `C:\foo`, ``},
|
|
|
|
{"windows", `C:\foo`, `bar`, `C:\foo\bar`, ``},
|
|
|
|
{"windows", `C:\foo`, `/bar`, `C:\bar`, ``},
|
|
|
|
{"windows", `C:\foo`, `\bar`, `C:\bar`, ``},
|
2017-08-22 18:25:31 -04:00
|
|
|
{"linux", ``, ``, ``, `cannot normalize nothing`},
|
2017-08-04 14:39:23 -04:00
|
|
|
{"linux", ``, `foo`, `/foo`, ``},
|
|
|
|
{"linux", ``, `/foo`, `/foo`, ``},
|
|
|
|
{"linux", `/foo`, `bar`, `/foo/bar`, ``},
|
|
|
|
{"linux", `/foo`, `/bar`, `/bar`, ``},
|
|
|
|
{"linux", `\a`, `b\c`, `/a/b/c`, ``},
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
for _, i := range tests {
|
2017-08-22 18:25:31 -04:00
|
|
|
r, e := normalizeWorkdir(i.platform, i.current, i.requested)
|
2016-05-02 21:33:59 -04:00
|
|
|
|
|
|
|
if i.etext != "" && e == nil {
|
2017-08-22 18:25:31 -04:00
|
|
|
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if i.etext != "" && e.Error() != i.etext {
|
2017-08-22 18:25:31 -04:00
|
|
|
t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if r != i.expected {
|
2017-08-22 18:25:31 -04:00
|
|
|
t.Fatalf("TestNormalizeWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|