mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
34 lines
967 B
Go
34 lines
967 B
Go
|
// +build !windows
|
||
|
|
||
|
package dockerfile
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNormaliseWorkdir(t *testing.T) {
|
||
|
testCases := []struct{ current, requested, expected, expectedError string }{
|
||
|
{``, ``, ``, `cannot normalise nothing`},
|
||
|
{``, `foo`, `/foo`, ``},
|
||
|
{``, `/foo`, `/foo`, ``},
|
||
|
{`/foo`, `bar`, `/foo/bar`, ``},
|
||
|
{`/foo`, `/bar`, `/bar`, ``},
|
||
|
}
|
||
|
|
||
|
for _, test := range testCases {
|
||
|
normalised, err := normaliseWorkdir(test.current, test.requested)
|
||
|
|
||
|
if test.expectedError != "" && err == nil {
|
||
|
t.Fatalf("NormaliseWorkdir should return an error %s, got nil", test.expectedError)
|
||
|
}
|
||
|
|
||
|
if test.expectedError != "" && err.Error() != test.expectedError {
|
||
|
t.Fatalf("NormaliseWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error())
|
||
|
}
|
||
|
|
||
|
if normalised != test.expected {
|
||
|
t.Fatalf("NormaliseWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalised)
|
||
|
}
|
||
|
}
|
||
|
}
|