File: cleanup.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 (108 lines) | stat: -rw-r--r-- 3,400 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
package buildtest

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
	"gitlab.com/gitlab-org/gitlab-runner/common"
)

func RunBuildWithCleanupGitClone(t *testing.T, build *common.Build) {
	build.Variables = append(
		build.Variables,
		common.JobVariable{Key: "GIT_STRATEGY", Value: "clone"},
		common.JobVariable{Key: "FF_ENABLE_JOB_CLEANUP", Value: "true"},
	)
	out, err := RunBuildReturningOutput(t, build)
	assert.NoError(t, err)
	assert.Contains(t, out, "Cleaning up project directory and file based variables")
}

func RunBuildWithCleanupGitFetch(t *testing.T, build *common.Build, untrackedFilename string) {
	build.Variables = append(
		build.Variables,
		common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"},
		common.JobVariable{Key: "FF_ENABLE_JOB_CLEANUP", Value: "true"},
	)

	out, err := RunBuildReturningOutput(t, build)
	assert.NoError(t, err)
	assert.Contains(t, out, "Cleaning up project directory and file based variables")
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFilename))
}

func RunBuildWithCleanupNormalSubmoduleStrategy(
	t *testing.T,
	build *common.Build,
	untrackedFileName,
	untrackedFileInSubmodule string,
) {
	build.Variables = append(
		build.Variables,
		common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"},
		common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "normal"},
		common.JobVariable{Key: "FF_ENABLE_JOB_CLEANUP", Value: "true"},
	)

	out, err := RunBuildReturningOutput(t, build)
	assert.NoError(t, err)

	assert.Contains(t, out, "Cleaning up project directory and file based variables")
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFileName))
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFileInSubmodule))
}

func RunBuildWithCleanupRecursiveSubmoduleStrategy(
	t *testing.T,
	build *common.Build,
	untrackedFileName,
	untrackedFileInSubmodule,
	untrackedFileInSubSubmodule string,
) {
	build.Variables = append(
		build.Variables,
		common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"},
		common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "recursive"},
		common.JobVariable{Key: "FF_ENABLE_JOB_CLEANUP", Value: "true"},
	)

	out, err := RunBuildReturningOutput(t, build)
	assert.NoError(t, err)

	assert.Contains(t, out, "Cleaning up project directory and file based variables")
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFileName))
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFileInSubmodule))
	assert.Contains(t, out, fmt.Sprintf("Removing %s", untrackedFileInSubSubmodule))
}

func GetNewUntrackedFileIntoSubmodulesCommands(
	untrackedFile,
	untrackedFileInSubmodule,
	untrackedFileInSubSubmodule string,
) []string {
	var untrackedFilesResult []string
	if untrackedFile != "" {
		untrackedFilesResult = append(
			untrackedFilesResult,
			fmt.Sprintf("echo 'this is an untracked file' >> %s", untrackedFile),
		)
	}
	if untrackedFileInSubmodule != "" {
		untrackedFilesResult = append(
			untrackedFilesResult,
			fmt.Sprintf(
				"echo 'this is an untracked file in the submodule' >> gitlab-grack/%s",
				untrackedFileInSubmodule,
			))
	}
	if untrackedFileInSubSubmodule != "" {
		untrackedFilesResult = append(
			untrackedFilesResult,
			fmt.Sprintf(
				"echo 'this is an untracked file in the sub-submodule' >> gitlab-grack/tests/example/%s",
				untrackedFileInSubSubmodule,
			))
	}
	return untrackedFilesResult
}