github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/builder/dockerfile/dispatchers_windows_test.go (about)

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