2016-05-02 21:33:59 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package dockerfile
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestNormaliseWorkdir(t *testing.T) {
|
|
|
|
tests := []struct{ current, requested, expected, etext string }{
|
|
|
|
{``, ``, ``, `cannot normalise nothing`},
|
2016-09-21 00:46:22 -04:00
|
|
|
{``, `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 '\'`},
|
2016-05-02 21:33:59 -04:00
|
|
|
{``, `a`, `C:\a`, ``},
|
|
|
|
{``, `c:\foo`, `C:\foo`, ``},
|
2016-09-21 00:46:22 -04:00
|
|
|
{``, `c:\\foo`, `C:\foo`, ``},
|
2016-05-02 21:33:59 -04:00
|
|
|
{``, `\foo`, `C:\foo`, ``},
|
2016-09-21 00:46:22 -04:00
|
|
|
{``, `\\foo`, `C:\foo`, ``},
|
2016-05-02 21:33:59 -04:00
|
|
|
{``, `/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 {
|
2016-09-21 00:46:22 -04:00
|
|
|
t.Fatalf("TestNormaliseWorkingDir 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 {
|
2016-09-21 00:46:22 -04:00
|
|
|
t.Fatalf("TestNormaliseWorkingDir 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 {
|
2016-09-21 00:46:22 -04:00
|
|
|
t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|