moby/builder/dockerfile/dispatchers_unix_test.go
Tomasz Kopczynski 9408b205f5 Builder dispatchers unit tests
Signed-off-by: Tomasz Kopczynski <tomek@kopczynski.net.pl>
2016-07-12 07:40:25 +02:00

33 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)
}
}
}