github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/builder/dockerfile/internals_windows_test.go (about)

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