2021-08-23 09:14:53 -04:00
|
|
|
//go:build !windows
|
2016-06-26 16:01:28 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2016-06-26 16:01:28 -04:00
|
|
|
|
|
|
|
import (
|
2017-08-04 14:39:23 -04:00
|
|
|
"runtime"
|
2016-06-26 16:01:28 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-08-22 18:25:31 -04:00
|
|
|
func TestNormalizeWorkdir(t *testing.T) {
|
2016-06-26 16:01:28 -04:00
|
|
|
testCases := []struct{ current, requested, expected, expectedError string }{
|
2017-08-22 18:25:31 -04:00
|
|
|
{``, ``, ``, `cannot normalize nothing`},
|
2016-06-26 16:01:28 -04:00
|
|
|
{``, `foo`, `/foo`, ``},
|
|
|
|
{``, `/foo`, `/foo`, ``},
|
|
|
|
{`/foo`, `bar`, `/foo/bar`, ``},
|
|
|
|
{`/foo`, `/bar`, `/bar`, ``},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
2017-08-22 18:25:31 -04:00
|
|
|
normalized, err := normalizeWorkdir(runtime.GOOS, test.current, test.requested)
|
2016-06-26 16:01:28 -04:00
|
|
|
|
|
|
|
if test.expectedError != "" && err == nil {
|
2017-08-22 18:25:31 -04:00
|
|
|
t.Fatalf("NormalizeWorkdir should return an error %s, got nil", test.expectedError)
|
2016-06-26 16:01:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if test.expectedError != "" && err.Error() != test.expectedError {
|
2017-08-22 18:25:31 -04:00
|
|
|
t.Fatalf("NormalizeWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
|
2016-06-26 16:01:28 -04:00
|
|
|
}
|
|
|
|
|
2017-08-22 18:25:31 -04:00
|
|
|
if normalized != test.expected {
|
|
|
|
t.Fatalf("NormalizeWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalized)
|
2016-06-26 16:01:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|