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
|
|
|
|
2017-05-25 17:03:29 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-05-25 17:03:29 -04:00
|
|
|
)
|
2016-05-02 21:33:59 -04:00
|
|
|
|
2017-08-22 18:25:31 -04:00
|
|
|
func TestNormalizeDest(t *testing.T) {
|
2016-05-02 21:33:59 -04:00
|
|
|
tests := []struct{ current, requested, expected, etext string }{
|
2017-05-25 17:03:29 -04:00
|
|
|
{``, `D:\`, ``, `Windows does not support destinations not on the system drive (C:)`},
|
|
|
|
{``, `e:/`, ``, `Windows does not support destinations not on the system drive (C:)`},
|
2016-05-02 21:33:59 -04:00
|
|
|
{`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`},
|
|
|
|
{`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`},
|
|
|
|
{`C`, ``, ``, `Current WorkingDir C is not platform consistent`},
|
2017-05-25 17:03:29 -04:00
|
|
|
{`D:\`, `.`, ``, "Windows does not support relative paths when WORKDIR is not the system drive"},
|
2016-05-02 21:33:59 -04:00
|
|
|
{``, `D`, `D`, ``},
|
|
|
|
{``, `./a1`, `.\a1`, ``},
|
|
|
|
{``, `.\b1`, `.\b1`, ``},
|
|
|
|
{``, `/`, `\`, ``},
|
|
|
|
{``, `\`, `\`, ``},
|
|
|
|
{``, `c:/`, `\`, ``},
|
|
|
|
{``, `c:\`, `\`, ``},
|
|
|
|
{``, `.`, `.`, ``},
|
|
|
|
{`C:\wdd`, `./a1`, `\wdd\a1`, ``},
|
|
|
|
{`C:\wde`, `.\b1`, `\wde\b1`, ``},
|
|
|
|
{`C:\wdf`, `/`, `\`, ``},
|
|
|
|
{`C:\wdg`, `\`, `\`, ``},
|
|
|
|
{`C:\wdh`, `c:/`, `\`, ``},
|
|
|
|
{`C:\wdi`, `c:\`, `\`, ``},
|
|
|
|
{`C:\wdj`, `.`, `\wdj`, ``},
|
|
|
|
{`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``},
|
|
|
|
{`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``},
|
|
|
|
{`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``},
|
|
|
|
{`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``},
|
|
|
|
}
|
2017-05-25 17:03:29 -04:00
|
|
|
for _, testcase := range tests {
|
|
|
|
msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
|
2017-08-03 20:22:00 -04:00
|
|
|
actual, err := normalizeDest(testcase.current, testcase.requested, "windows")
|
2017-05-25 17:03:29 -04:00
|
|
|
if testcase.etext == "" {
|
2018-03-13 15:28:34 -04:00
|
|
|
if !assert.Check(t, err, msg) {
|
2017-05-25 17:03:29 -04:00
|
|
|
continue
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(testcase.expected, actual), msg)
|
2017-05-25 17:03:29 -04:00
|
|
|
} else {
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, testcase.etext))
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|