github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/builder/dockerfile/dispatchers_windows_test.go (about)

     1  // +build windows
     2  
     3  package dockerfile
     4  
     5  import "testing"
     6  
     7  func TestNormaliseWorkdir(t *testing.T) {
     8  	tests := []struct{ current, requested, expected, etext string }{
     9  		{``, ``, ``, `cannot normalise nothing`},
    10  		{``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
    11  		{``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
    12  		{`c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
    13  		{`c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
    14  		{``, `a`, `C:\a`, ``},
    15  		{``, `c:\foo`, `C:\foo`, ``},
    16  		{``, `c:\\foo`, `C:\foo`, ``},
    17  		{``, `\foo`, `C:\foo`, ``},
    18  		{``, `\\foo`, `C:\foo`, ``},
    19  		{``, `/foo`, `C:\foo`, ``},
    20  		{``, `C:/foo`, `C:\foo`, ``},
    21  		{`C:\foo`, `bar`, `C:\foo\bar`, ``},
    22  		{`C:\foo`, `/bar`, `C:\bar`, ``},
    23  		{`C:\foo`, `\bar`, `C:\bar`, ``},
    24  	}
    25  	for _, i := range tests {
    26  		r, e := normaliseWorkdir(i.current, i.requested)
    27  
    28  		if i.etext != "" && e == nil {
    29  			t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
    30  		}
    31  
    32  		if i.etext != "" && e.Error() != i.etext {
    33  			t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
    34  		}
    35  
    36  		if r != i.expected {
    37  			t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
    38  		}
    39  	}
    40  }