github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/builder/dockerfile/internals_windows_test.go (about) 1 // +build windows 2 3 package dockerfile 4 5 import "testing" 6 7 func TestNormaliseDest(t *testing.T) { 8 tests := []struct{ current, requested, expected, etext string }{ 9 {``, `D:\`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`}, 10 {``, `e:/`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`}, 11 {`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`}, 12 {`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`}, 13 {`C`, ``, ``, `Current WorkingDir C is not platform consistent`}, 14 {`D:\`, `.`, ``, "Windows does not support TEST with relative paths when WORKDIR is not the system drive"}, 15 {``, `D`, `D`, ``}, 16 {``, `./a1`, `.\a1`, ``}, 17 {``, `.\b1`, `.\b1`, ``}, 18 {``, `/`, `\`, ``}, 19 {``, `\`, `\`, ``}, 20 {``, `c:/`, `\`, ``}, 21 {``, `c:\`, `\`, ``}, 22 {``, `.`, `.`, ``}, 23 {`C:\wdd`, `./a1`, `\wdd\a1`, ``}, 24 {`C:\wde`, `.\b1`, `\wde\b1`, ``}, 25 {`C:\wdf`, `/`, `\`, ``}, 26 {`C:\wdg`, `\`, `\`, ``}, 27 {`C:\wdh`, `c:/`, `\`, ``}, 28 {`C:\wdi`, `c:\`, `\`, ``}, 29 {`C:\wdj`, `.`, `\wdj`, ``}, 30 {`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``}, 31 {`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``}, 32 {`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``}, 33 {`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``}, 34 } 35 for _, i := range tests { 36 got, err := normaliseDest("TEST", i.current, i.requested) 37 if err != nil && i.etext == "" { 38 t.Fatalf("TestNormaliseDest Got unexpected error %q for %s %s. ", err.Error(), i.current, i.requested) 39 } 40 if i.etext != "" && ((err == nil) || (err != nil && err.Error() != i.etext)) { 41 if err == nil { 42 t.Fatalf("TestNormaliseDest Expected an error for %s %s but didn't get one", i.current, i.requested) 43 } else { 44 t.Fatalf("TestNormaliseDest Wrong error text for %s %s - %s", i.current, i.requested, err.Error()) 45 } 46 } 47 if i.etext == "" && got != i.expected { 48 t.Fatalf("TestNormaliseDest Expected %q for %q and %q. Got %q", i.expected, i.current, i.requested, got) 49 } 50 } 51 }