Skip to content
Snippets Groups Projects

Native Step Runner Integration for Docker Executor

Merged Axel von Bertoldi requested to merge avonbertoldi/47414/steps-integration-docker into main
2 unresolved threads
1 file
+ 114
0
Compare changes
  • Side-by-side
  • Inline
  • 4dc0a26a
    Docker executor integration tests · 4dc0a26a
    Axel von Bertoldi authored
    The goal here is to make sure we can execute steps in the various ways
    they can be sent from GitLab:
    - script step.
    - local step.
    - remote step.
    - make sure file variables work.
    - make sure job variables are not injected into the build container.
    
    We'd also like a job to run github action, but I have not been able to
    make that one work yet.
    
    Note that in the near future, these test might be flaky since we don't
    version the step-runner image, and changes there might brake tests here.
    To deal with that we skip the test if the variable CI_SKIP_STEPS_TESTS
    is set.
//go:build integration
package docker_test
import (
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/common/buildtest"
"gitlab.com/gitlab-org/gitlab-runner/helpers"
"gitlab.com/gitlab-org/gitlab-runner/helpers/featureflags"
"gitlab.com/gitlab-org/gitlab-runner/helpers/test"
)
var successAlwaysWantOut = []string{
`Executing "step_run" stage of the job script`,
"Job succeeded",
}
func Test_StepsIntegration(t *testing.T) {
test.SkipIfGitLabCIOn(t, test.OSWindows)
helpers.SkipIntegrationTests(t, "docker", "info")
test.SkipIfVariable(t, "CI_SKIP_STEPS_TESTS")
tests := map[string]struct {
steps string
variables common.JobVariables
services common.Services
wantOut []string
wantErr bool
}{
"script": {
steps: `- name: echo
script: echo foo bar baz
- name: ls
script: ls -lh
- name: env
script: env`,
wantOut: []string{
"foo bar baz",
"PWD=/builds/gitlab-org/ci-cd/gitlab-runner-pipeline-tests/gitlab-test",
},
},
"remote step": {
steps: `- name: echo
step: "https://gitlab.com/gitlab-org/ci-cd/runner-tools/echo-step@v1"
inputs:
echo: foo bar baz`,
wantOut: []string{"foo bar baz"},
},
"local step": {
steps: `- name: localecho
step: "./steps/echo"
inputs:
message: foo bar baz`,
wantOut: []string{"foo bar baz"},
},
"file variable": {
steps: `- name: cat
script: cat ${{ job.A_FILE_VAR }}`,
variables: common.JobVariables{{Key: "A_FILE_VAR", Value: "oh this is soo secret", File: true}},
wantOut: []string{"oh this is soo secret"},
},
"job variables should not appear in environment": {
steps: `- name: echo
script: echo ${{ env.FLIN_FLAN_FLON }}`,
variables: common.JobVariables{{Key: "FLIN_FLAN_FLON", Value: "flin, flan, flon"}},
wantOut: []string{
"ERROR: Job failed: container",
`env.FLIN_FLAN_FLON: the "FLIN_FLAN_FLON" was not found`,
},
wantErr: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
successfulBuild, err := common.GetRemoteStepsBuildResponse(tt.steps)
assert.NoError(t, err)
successfulBuild.Services = tt.services
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{Key: featureflags.UseNativeSteps, Value: "true", Public: true})
successfulBuild.Variables = append(successfulBuild.Variables, tt.variables...)
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "registry.gitlab.com/gitlab-org/step-runner:v0",
PullPolicy: common.StringOrArray{common.PullPolicyAlways},
Privileged: true,
},
},
},
}
wantOut := tt.wantOut
out, err := buildtest.RunBuildReturningOutput(t, build)
if !tt.wantErr {
assert.NoError(t, err)
wantOut = append(wantOut, successAlwaysWantOut...)
} else {
assert.Error(t, err)
}
for _, want := range wantOut {
assert.Contains(t, out, want)
}
})
}
}
Loading