Commit 5105b237 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix spec failures

parent dd32fd36
Pipeline #27382276 passed with stages
in 25 minutes and 39 seconds
......@@ -83,8 +83,11 @@ func mockingExecutionStack(t *testing.T, executorName string, maxBuilds int, job
}
//ExecutorProvider
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Times(maxBuilds + 1)
p.On("Create").Return(&e).Times(maxBuilds)
p.On("GetFeatures", mock.Anything).Times(maxBuilds)
p.On("Acquire", mock.Anything).Return(&common.MockExecutorData{}, nil).Times(maxBuilds)
p.On("Release", mock.Anything, mock.Anything).Return(nil).Times(maxBuilds)
......
......@@ -26,8 +26,11 @@ func TestBuildRun(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor only once
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// We run everything once
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
......@@ -71,8 +74,11 @@ func TestRetryPrepare(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Times(3)
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).
......@@ -112,8 +118,11 @@ func TestPrepareFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Times(3)
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).
......@@ -144,8 +153,11 @@ func TestPrepareFailureOnBuildError(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Times(1)
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).
......@@ -182,8 +194,11 @@ func TestRunFailureRunsAfterScriptAndArtifactsOnFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -224,8 +239,11 @@ func TestGetSourcesRunFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -264,8 +282,11 @@ func TestArtifactDownloadRunFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -306,8 +327,11 @@ func TestArtifactUploadRunFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -357,8 +381,11 @@ func TestRestoreCacheRunFailure(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -397,8 +424,11 @@ func TestRunWrongAttempts(t *testing.T) {
defer p.AssertExpectations(t)
// Create executor
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e)
p.On("GetFeatures", mock.Anything).Once()
// Prepare plan
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil)
......@@ -433,8 +463,11 @@ func TestRunSuccessOnSecondAttempt(t *testing.T) {
p := MockExecutorProvider{}
// Create executor only once
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
p.On("GetFeatures", mock.Anything).Once()
// We run everything once
e.On("Prepare", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
......
......@@ -3,6 +3,7 @@ package common
import (
"context"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
)
......@@ -75,8 +76,8 @@ func validateExecutorProvider(provider ExecutorProvider) error {
return errors.New("cannot create executor")
}
if provider.GetFeatures(&FeaturesInfo{}) != nil {
return errors.New("cannot get features")
if err := provider.GetFeatures(&FeaturesInfo{}); err != nil {
return fmt.Errorf("cannot get features: %v", err)
}
return nil
......
......@@ -93,6 +93,7 @@ type VersionInfo struct {
Platform string `json:"platform,omitempty"`
Architecture string `json:"architecture,omitempty"`
Executor string `json:"executor,omitempty"`
Shell string `json:"shell,omitempty"`
Features FeaturesInfo `json:"features"`
}
......
......@@ -132,19 +132,18 @@ func (n *GitLabClient) getRunnerVersion(config common.RunnerConfig) common.Versi
Platform: runtime.GOOS,
Architecture: runtime.GOARCH,
Executor: config.Executor,
Shell: config.Shell,
}
var shellName = config.Shell
if executor := common.GetExecutor(config.Executor); executor != nil {
executor.GetFeatures(&info.Features)
if shellName == "" {
shellName = executor.GetDefaultShell()
if info.Shell == "" {
info.Shell = executor.GetDefaultShell()
}
}
if shell := common.GetShell(shellName); shell != nil {
if shell := common.GetShell(info.Shell); shell != nil {
shell.GetFeatures(&info.Features)
}
......
......@@ -13,6 +13,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
. "gitlab.com/gitlab-org/gitlab-runner/common"
......@@ -982,3 +983,56 @@ func TestArtifactsDownload(t *testing.T) {
state = c.DownloadArtifacts(fileNotFoundTokenCredentials, artifactsFileName)
assert.Equal(t, DownloadNotFound, state, "Artifacts should be bit downloaded if it's not found")
}
func TestRunnerVersion(t *testing.T) {
c := NewGitLabClient()
info := c.getRunnerVersion(RunnerConfig{
RunnerSettings: RunnerSettings{
Executor: "my-executor",
Shell: "my-shell",
},
})
assert.NotEmpty(t, info.Name)
assert.NotEmpty(t, info.Version)
assert.NotEmpty(t, info.Revision)
assert.NotEmpty(t, info.Platform)
assert.NotEmpty(t, info.Architecture)
assert.Equal(t, "my-executor", info.Executor)
assert.Equal(t, "my-shell", info.Shell)
}
func TestRunnerVersionToGetExecutorAndShellFeaturesWithTheDefaultShell(t *testing.T) {
executorProvider := MockExecutorProvider{}
defer executorProvider.AssertExpectations(t)
executorProvider.On("GetDefaultShell").Return("my-default-executor-shell").Twice()
executorProvider.On("CanCreate").Return(true).Once()
executorProvider.On("GetFeatures", mock.Anything).Return(nil).Run(func(args mock.Arguments) {
features := args[0].(*FeaturesInfo)
features.Shared = true
})
RegisterExecutor("my-test-executor", &executorProvider)
shell := MockShell{}
defer shell.AssertExpectations(t)
shell.On("GetName").Return("my-default-executor-shell")
shell.On("GetFeatures", mock.Anything).Return(nil).Run(func(args mock.Arguments) {
features := args[0].(*FeaturesInfo)
features.Variables = true
})
RegisterShell(&shell)
c := NewGitLabClient()
info := c.getRunnerVersion(RunnerConfig{
RunnerSettings: RunnerSettings{
Executor: "my-test-executor",
Shell: "",
},
})
assert.Equal(t, "my-test-executor", info.Executor)
assert.Equal(t, "my-default-executor-shell", info.Shell)
assert.False(t, info.Features.Artifacts, "dry-run that this is not enabled")
assert.True(t, info.Features.Shared, "feature is enabled by executor")
assert.True(t, info.Features.Variables, "feature is enabled by shell")
}
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