Add test for branch change on fetching code change

In
gitlab-org/gitlab-runner#4080 (comment 154587337)
it was mentioed that when using the shell runner on cmd and the repo is
already cloned, it is not checking out the correct directory. Using
delayed expansion for error handling fixes this. Added a test to have
this case covered.
parent 8d129222
......@@ -20,7 +20,7 @@ import (
)
const (
repoRemoteURL = "https://gitlab.com/gitlab-org/ci-cd/tests/gitlab-test.git"
RepoRemoteURL = "https://gitlab.com/gitlab-org/ci-cd/tests/gitlab-test.git"
repoRefType = RefTypeBranch
......@@ -76,7 +76,7 @@ func GetRemoteSuccessfulBuild() (JobResponse, error) {
func GetRemoteSuccessfulLFSBuild() (JobResponse, error) {
response, err := GetRemoteBuildResponse("echo Hello World")
response.GitInfo = GetLFSGitInfo(repoRemoteURL)
response.GitInfo = GetLFSGitInfo(RepoRemoteURL)
return response, err
}
......@@ -187,7 +187,7 @@ func getBuildResponse(repoURL string, commands []string) JobResponse {
}
func GetRemoteBuildResponse(commands ...string) (JobResponse, error) {
return getBuildResponse(repoRemoteURL, commands), nil
return getBuildResponse(RepoRemoteURL, commands), nil
}
func GetLocalBuildResponse(commands ...string) (JobResponse, error) {
......
......@@ -800,6 +800,26 @@ func TestBuildWithUntrackedDirFromPreviousBuild(t *testing.T) {
})
}
func TestBuildChangesBranchesWhenFetchingRepo(t *testing.T) {
shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
assert.NoError(t, err)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository")
// Another build using the same repo but different branch.
build.GitInfo = common.GetLFSGitInfo(common.RepoRemoteURL)
out, err = runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Checking out 2371dd05 as add-lfs-object...")
})
}
func TestInteractiveTerminal(t *testing.T) {
cases := []struct {
app string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment