github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/internal/volumes/parser/windows_parser_test.go (about) 1 // +build windows 2 3 package parser 4 5 import ( 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestWindowsParser_ParseVolume(t *testing.T) { 12 testCases := map[string]struct { 13 volumeSpec string 14 expectedParts *Volume 15 expectedError error 16 }{ 17 "empty": { 18 volumeSpec: "", 19 expectedError: NewInvalidVolumeSpecErr(""), 20 }, 21 "destination only": { 22 volumeSpec: `c:\destination`, 23 expectedParts: &Volume{Destination: `c:\destination`}, 24 }, 25 "source and destination": { 26 volumeSpec: `c:\source:c:\destination`, 27 expectedParts: &Volume{Source: `c:\source`, Destination: `c:\destination`}, 28 }, 29 "source and destination case insensitive disk mount": { 30 volumeSpec: `C:\source:C:\destination`, 31 expectedParts: &Volume{Source: `C:\source`, Destination: `C:\destination`}, 32 }, 33 "source and destination case insensitive": { 34 volumeSpec: `c:\Source:c:\Destination`, 35 expectedParts: &Volume{Source: `c:\Source`, Destination: `c:\Destination`}, 36 }, 37 "destination and mode": { 38 volumeSpec: `c:\destination:rw`, 39 expectedParts: &Volume{Destination: `c:\destination`, Mode: "rw"}, 40 }, 41 "all values": { 42 volumeSpec: `c:\source:c:\destination:rw`, 43 expectedParts: &Volume{Source: `c:\source`, Destination: `c:\destination`, Mode: "rw"}, 44 }, 45 "too much colons": { 46 volumeSpec: `c:\source:c:\destination:rw:something`, 47 expectedError: NewInvalidVolumeSpecErr(`c:\source:c:\destination:rw:something`), 48 }, 49 "invalid source": { 50 volumeSpec: `/destination:c:\destination`, 51 expectedError: NewInvalidVolumeSpecErr(`/destination:c:\destination`), 52 }, 53 "named source": { 54 volumeSpec: `volume_name:c:\destination`, 55 expectedParts: &Volume{Source: "volume_name", Destination: `c:\destination`}, 56 }, 57 } 58 59 for testName, testCase := range testCases { 60 t.Run(testName, func(t *testing.T) { 61 parser := NewWindowsParser() 62 parts, err := parser.ParseVolume(testCase.volumeSpec) 63 64 if testCase.expectedError == nil { 65 assert.NoError(t, err) 66 } else { 67 assert.EqualError(t, err, testCase.expectedError.Error()) 68 } 69 70 assert.Equal(t, testCase.expectedParts, parts) 71 }) 72 } 73 }