github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/builder/dockerfile/dispatchers_windows_test.go (about)

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