github.com/nilium/gitlab-runner@v12.5.0+incompatible/commands/register_windows_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"gitlab.com/gitlab-org/gitlab-runner/common"
    10  )
    11  
    12  func TestRegisterDefaultWindowsDockerCacheVolume(t *testing.T) {
    13  	testCases := map[string]struct {
    14  		userDefinedVolumes []string
    15  		expectedVolumes    []string
    16  	}{
    17  		"user did not define anything": {
    18  			userDefinedVolumes: []string{},
    19  			expectedVolumes:    []string{defaultDockerWindowCacheDir},
    20  		},
    21  		"user defined an extra volume": {
    22  			userDefinedVolumes: []string{"c:\\Users\\SomeUser\\config.json:c:\\config.json"},
    23  			expectedVolumes:    []string{defaultDockerWindowCacheDir, "c:\\Users\\SomeUser\\config.json:c:\\config.json"},
    24  		},
    25  		"user defined volume binding to default cache dir": {
    26  			userDefinedVolumes: []string{fmt.Sprintf("c:\\Users\\SomeUser\\cache:%s", defaultDockerWindowCacheDir)},
    27  			expectedVolumes:    []string{fmt.Sprintf("c:\\Users\\SomeUser\\cache:%s", defaultDockerWindowCacheDir)},
    28  		},
    29  		"user defined cache as source leads to incorrect parsing of volume and never adds cache volume": {
    30  			userDefinedVolumes: []string{"c:\\cache:c:\\User\\ContainerAdministrator\\cache"},
    31  			expectedVolumes:    []string{"c:\\cache:c:\\User\\ContainerAdministrator\\cache"},
    32  		},
    33  	}
    34  
    35  	for name, testCase := range testCases {
    36  		t.Run(name, func(t *testing.T) {
    37  			s := setupDockerRegisterCommand(&common.DockerConfig{
    38  				Volumes: testCase.userDefinedVolumes,
    39  			})
    40  
    41  			s.askDockerWindows()
    42  			assert.ElementsMatch(t, testCase.expectedVolumes, s.Docker.Volumes)
    43  		})
    44  	}
    45  }
    46  
    47  func TestDefaultWindowsShell(t *testing.T) {
    48  	tests := []struct {
    49  		shell         string
    50  		expectedShell string
    51  	}{
    52  		{
    53  			shell:         "cmd",
    54  			expectedShell: "cmd",
    55  		},
    56  		{
    57  			shell:         "powershell",
    58  			expectedShell: "powershell",
    59  		},
    60  		{
    61  			shell:         "",
    62  			expectedShell: "powershell",
    63  		},
    64  	}
    65  
    66  	for _, tt := range tests {
    67  		t.Run(tt.shell, func(t *testing.T) {
    68  			cmd := newRegisterCommand()
    69  			cmd.Shell = tt.shell
    70  			cmd.Executor = "shell"
    71  
    72  			cmd.askExecutorOptions()
    73  
    74  			assert.Equal(t, tt.expectedShell, cmd.Shell)
    75  		})
    76  	}
    77  }