github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/builder/dockerfile/internals_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 (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"gotest.tools/v3/assert"
    11  	is "gotest.tools/v3/assert/cmp"
    12  )
    13  
    14  func TestNormalizeDest(t *testing.T) {
    15  	tests := []struct{ current, requested, expected, etext string }{
    16  		{``, `D:\`, ``, `Windows does not support destinations not on the system drive (C:)`},
    17  		{``, `e:/`, ``, `Windows does not support destinations not on the system drive (C:)`},
    18  		{`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`},
    19  		{`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`},
    20  		{`C`, ``, ``, `Current WorkingDir C is not platform consistent`},
    21  		{`D:\`, `.`, ``, "Windows does not support relative paths when WORKDIR is not the system drive"},
    22  		{``, `D`, `D`, ``},
    23  		{``, `./a1`, `.\a1`, ``},
    24  		{``, `.\b1`, `.\b1`, ``},
    25  		{``, `/`, `\`, ``},
    26  		{``, `\`, `\`, ``},
    27  		{``, `c:/`, `\`, ``},
    28  		{``, `c:\`, `\`, ``},
    29  		{``, `.`, `.`, ``},
    30  		{`C:\wdd`, `./a1`, `\wdd\a1`, ``},
    31  		{`C:\wde`, `.\b1`, `\wde\b1`, ``},
    32  		{`C:\wdf`, `/`, `\`, ``},
    33  		{`C:\wdg`, `\`, `\`, ``},
    34  		{`C:\wdh`, `c:/`, `\`, ``},
    35  		{`C:\wdi`, `c:\`, `\`, ``},
    36  		{`C:\wdj`, `.`, `\wdj`, ``},
    37  		{`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``},
    38  		{`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``},
    39  		{`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``},
    40  		{`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``},
    41  	}
    42  	for _, testcase := range tests {
    43  		msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
    44  		actual, err := normalizeDest(testcase.current, testcase.requested, "windows")
    45  		if testcase.etext == "" {
    46  			if !assert.Check(t, err, msg) {
    47  				continue
    48  			}
    49  			assert.Check(t, is.Equal(testcase.expected, actual), msg)
    50  		} else {
    51  			assert.Check(t, is.ErrorContains(err, testcase.etext))
    52  		}
    53  	}
    54  }