File: service_integration_test.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (117 lines) | stat: -rw-r--r-- 2,713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build integration
// +build integration

package commands_test

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/urfave/cli"
	"gitlab.com/gitlab-org/gitlab-runner/commands"

	"gitlab.com/gitlab-org/gitlab-runner/helpers"
)

func newTestGetServiceArgumentsCommand(t *testing.T, expectedArgs []string) func(*cli.Context) {
	return func(c *cli.Context) {
		arguments := commands.GetServiceArguments(c)

		for _, arg := range expectedArgs {
			assert.Contains(t, arguments, arg)
		}
	}
}

func testServiceCommandRun(command func(*cli.Context), args ...string) {
	app := cli.NewApp()
	app.Commands = []cli.Command{
		{
			Name:   "test-command",
			Action: command,
			Flags:  commands.GetInstallFlags(),
		},
	}

	args = append([]string{"binary", "test-command"}, args...)
	_ = app.Run(args)
}

type getServiceArgumentsTestCase struct {
	cliFlags     []string
	expectedArgs []string
}

func TestGetServiceArguments(t *testing.T) {
	tests := []getServiceArgumentsTestCase{
		{
			expectedArgs: []string{
				"--working-directory", helpers.GetCurrentWorkingDirectory(),
				"--config", commands.GetDefaultConfigFile(),
				"--service", "gitlab-runner",
				"--syslog",
			},
		},
		{
			cliFlags: []string{
				"--config", "/tmp/config.toml",
			},
			expectedArgs: []string{
				"--working-directory", helpers.GetCurrentWorkingDirectory(),
				"--config", "/tmp/config.toml",
				"--service", "gitlab-runner",
				"--syslog",
			},
		},
		{
			cliFlags: []string{
				"--working-directory", "/tmp",
			},
			expectedArgs: []string{
				"--working-directory", "/tmp",
				"--config", commands.GetDefaultConfigFile(),
				"--service", "gitlab-runner",
				"--syslog",
			},
		},
		{
			cliFlags: []string{
				"--service", "gitlab-runner-service-name",
			},
			expectedArgs: []string{
				"--working-directory", helpers.GetCurrentWorkingDirectory(),
				"--config", commands.GetDefaultConfigFile(),
				"--service", "gitlab-runner-service-name",
				"--syslog",
			},
		},
		{
			cliFlags: []string{
				"--syslog=true",
			},
			expectedArgs: []string{
				"--working-directory", helpers.GetCurrentWorkingDirectory(),
				"--config", commands.GetDefaultConfigFile(),
				"--service", "gitlab-runner",
				"--syslog",
			},
		},
		{
			cliFlags: []string{
				"--syslog=false",
			},
			expectedArgs: []string{
				"--working-directory", helpers.GetCurrentWorkingDirectory(),
				"--config", commands.GetDefaultConfigFile(),
				"--service", "gitlab-runner",
			},
		},
	}

	for id, testCase := range tests {
		t.Run(fmt.Sprintf("case-%d", id), func(t *testing.T) {
			testServiceCommandRun(newTestGetServiceArgumentsCommand(t, testCase.expectedArgs), testCase.cliFlags...)
		})
	}
}