2016-05-02 21:33:59 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package dockerfile
|
|
|
|
|
2017-05-25 17:03:29 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-23 17:35:09 -04:00
|
|
|
"github.com/docker/docker/internal/testutil"
|
2017-05-25 17:03:29 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
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-22 18:25:31 -04:00
|
|
|
actual, err := normalizeDest(testcase.current, testcase.requested)
|
2017-05-25 17:03:29 -04:00
|
|
|
if testcase.etext == "" {
|
|
|
|
if !assert.NoError(t, err, msg) {
|
|
|
|
continue
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
2017-05-25 17:03:29 -04:00
|
|
|
assert.Equal(t, testcase.expected, actual, msg)
|
|
|
|
} else {
|
|
|
|
testutil.ErrorContains(t, err, testcase.etext)
|
2016-05-02 21:33:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|