Use already existing variable value when writing git configuration

parent fb161916
Pipeline #27780809 passed with stages
in 41 minutes and 47 seconds
......@@ -154,7 +154,7 @@ mocks: $(MOCKERY)
GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./vendor/github.com/ayufan/golang-kardianos-service -output=./helpers/service/mocks -name='(Interface|Logger)'
GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./helpers/docker -all -inpkg
GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./common -all -inpkg
GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./shells -name fakeIAMCredentialsProvider -inpkg
GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./shells -all -inpkg
test-docker:
make test-docker-image IMAGE=centos:6 TYPE=rpm
......
......@@ -54,8 +54,7 @@ func (b *AbstractShell) writeGitSSLConfig(w ShellWriter, build *common.Build, wh
}
key := fmt.Sprintf("http.%s.%s", host, config)
value := w.TmpFile(variable)
w.Command("git", append(args, key, value)...)
w.Command("git", append(args, key, w.EnvVariableKey(variable))...)
}
return
......
......@@ -9,7 +9,6 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/tls"
"gitlab.com/gitlab-org/gitlab-runner/shells/mocks"
)
func TestWriteGitSSLConfig(t *testing.T) {
......@@ -30,14 +29,14 @@ func TestWriteGitSSLConfig(t *testing.T) {
},
}
mockWriter := new(mocks.ShellWriter)
mockWriter.On("TmpFile", tls.VariableCAFile).Return(tls.VariableCAFile).Once()
mockWriter.On("TmpFile", tls.VariableCertFile).Return(tls.VariableCertFile).Once()
mockWriter.On("TmpFile", tls.VariableKeyFile).Return(tls.VariableKeyFile).Once()
mockWriter := new(MockShellWriter)
mockWriter.On("EnvVariableKey", tls.VariableCAFile).Return("VariableCAFile").Once()
mockWriter.On("EnvVariableKey", tls.VariableCertFile).Return("VariableCertFile").Once()
mockWriter.On("EnvVariableKey", tls.VariableKeyFile).Return("VariableKeyFile").Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslCAInfo"), tls.VariableCAFile).Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslCert"), tls.VariableCertFile).Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslKey"), tls.VariableKeyFile).Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslCAInfo"), "VariableCAFile").Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslCert"), "VariableCertFile").Once()
mockWriter.On("Command", "git", "config", fmt.Sprintf("http.%s.%s", gitlabURL, "sslKey"), "VariableKeyFile").Once()
shell.writeGitSSLConfig(mockWriter, build, nil)
......@@ -97,7 +96,7 @@ func TestWriteWritingArtifactsOnSuccess(t *testing.T) {
Build: build,
}
mockWriter := new(mocks.ShellWriter)
mockWriter := new(MockShellWriter)
defer mockWriter.AssertExpectations(t)
mockWriter.On("Variable", mock.Anything)
mockWriter.On("Cd", mock.Anything)
......@@ -157,7 +156,7 @@ func TestWriteWritingArtifactsOnFailure(t *testing.T) {
Build: build,
}
mockWriter := new(mocks.ShellWriter)
mockWriter := new(MockShellWriter)
defer mockWriter.AssertExpectations(t)
mockWriter.On("Variable", mock.Anything)
mockWriter.On("Cd", mock.Anything)
......
......@@ -85,6 +85,10 @@ func (b *BashWriter) TmpFile(name string) string {
return b.Absolute(path.Join(b.TemporaryPath, name))
}
func (b *BashWriter) EnvVariableKey(name string) string {
return fmt.Sprintf("$%s", name)
}
func (b *BashWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.TmpFile(variable.Key)
......
......@@ -106,6 +106,10 @@ func (b *CmdWriter) TmpFile(name string) string {
return helpers.ToBackslash(filePath)
}
func (b *CmdWriter) EnvVariableKey(name string) string {
return fmt.Sprintf("%%%s%%", name)
}
func (b *CmdWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.TmpFile(variable.Key)
......
package mocks
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Code generated by mockery v1.0.0
// This comment works around https://github.com/vektra/mockery/issues/155
package shells
import common "gitlab.com/gitlab-org/gitlab-runner/common"
import mock "github.com/stretchr/testify/mock"
// ShellWriter is an autogenerated mock type for the ShellWriter type
type ShellWriter struct {
// MockShellWriter is an autogenerated mock type for the ShellWriter type
type MockShellWriter struct {
mock.Mock
}
// Absolute provides a mock function with given fields: path
func (_m *ShellWriter) Absolute(path string) string {
func (_m *MockShellWriter) Absolute(path string) string {
ret := _m.Called(path)
var r0 string
......@@ -25,17 +27,17 @@ func (_m *ShellWriter) Absolute(path string) string {
}
// Cd provides a mock function with given fields: path
func (_m *ShellWriter) Cd(path string) {
func (_m *MockShellWriter) Cd(path string) {
_m.Called(path)
}
// CheckForErrors provides a mock function with given fields:
func (_m *ShellWriter) CheckForErrors() {
func (_m *MockShellWriter) CheckForErrors() {
_m.Called()
}
// Command provides a mock function with given fields: command, arguments
func (_m *ShellWriter) Command(command string, arguments ...string) {
func (_m *MockShellWriter) Command(command string, arguments ...string) {
_va := make([]interface{}, len(arguments))
for _i := range arguments {
_va[_i] = arguments[_i]
......@@ -47,22 +49,36 @@ func (_m *ShellWriter) Command(command string, arguments ...string) {
}
// Else provides a mock function with given fields:
func (_m *ShellWriter) Else() {
func (_m *MockShellWriter) Else() {
_m.Called()
}
// EmptyLine provides a mock function with given fields:
func (_m *ShellWriter) EmptyLine() {
func (_m *MockShellWriter) EmptyLine() {
_m.Called()
}
// EndIf provides a mock function with given fields:
func (_m *ShellWriter) EndIf() {
func (_m *MockShellWriter) EndIf() {
_m.Called()
}
// EnvVariableKey provides a mock function with given fields: name
func (_m *MockShellWriter) EnvVariableKey(name string) string {
ret := _m.Called(name)
var r0 string
if rf, ok := ret.Get(0).(func(string) string); ok {
r0 = rf(name)
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// Error provides a mock function with given fields: fmt, arguments
func (_m *ShellWriter) Error(fmt string, arguments ...interface{}) {
func (_m *MockShellWriter) Error(fmt string, arguments ...interface{}) {
var _ca []interface{}
_ca = append(_ca, fmt)
_ca = append(_ca, arguments...)
......@@ -70,7 +86,7 @@ func (_m *ShellWriter) Error(fmt string, arguments ...interface{}) {
}
// IfCmd provides a mock function with given fields: cmd, arguments
func (_m *ShellWriter) IfCmd(cmd string, arguments ...string) {
func (_m *MockShellWriter) IfCmd(cmd string, arguments ...string) {
_va := make([]interface{}, len(arguments))
for _i := range arguments {
_va[_i] = arguments[_i]
......@@ -82,7 +98,7 @@ func (_m *ShellWriter) IfCmd(cmd string, arguments ...string) {
}
// IfCmdWithOutput provides a mock function with given fields: cmd, arguments
func (_m *ShellWriter) IfCmdWithOutput(cmd string, arguments ...string) {
func (_m *MockShellWriter) IfCmdWithOutput(cmd string, arguments ...string) {
_va := make([]interface{}, len(arguments))
for _i := range arguments {
_va[_i] = arguments[_i]
......@@ -94,27 +110,27 @@ func (_m *ShellWriter) IfCmdWithOutput(cmd string, arguments ...string) {
}
// IfDirectory provides a mock function with given fields: path
func (_m *ShellWriter) IfDirectory(path string) {
func (_m *MockShellWriter) IfDirectory(path string) {
_m.Called(path)
}
// IfFile provides a mock function with given fields: file
func (_m *ShellWriter) IfFile(file string) {
func (_m *MockShellWriter) IfFile(file string) {
_m.Called(file)
}
// Line provides a mock function with given fields: text
func (_m *ShellWriter) Line(text string) {
func (_m *MockShellWriter) Line(text string) {
_m.Called(text)
}
// MkDir provides a mock function with given fields: path
func (_m *ShellWriter) MkDir(path string) {
func (_m *MockShellWriter) MkDir(path string) {
_m.Called(path)
}
// MkTmpDir provides a mock function with given fields: name
func (_m *ShellWriter) MkTmpDir(name string) string {
func (_m *MockShellWriter) MkTmpDir(name string) string {
ret := _m.Called(name)
var r0 string
......@@ -128,7 +144,7 @@ func (_m *ShellWriter) MkTmpDir(name string) string {
}
// Notice provides a mock function with given fields: fmt, arguments
func (_m *ShellWriter) Notice(fmt string, arguments ...interface{}) {
func (_m *MockShellWriter) Notice(fmt string, arguments ...interface{}) {
var _ca []interface{}
_ca = append(_ca, fmt)
_ca = append(_ca, arguments...)
......@@ -136,7 +152,7 @@ func (_m *ShellWriter) Notice(fmt string, arguments ...interface{}) {
}
// Print provides a mock function with given fields: fmt, arguments
func (_m *ShellWriter) Print(fmt string, arguments ...interface{}) {
func (_m *MockShellWriter) Print(fmt string, arguments ...interface{}) {
var _ca []interface{}
_ca = append(_ca, fmt)
_ca = append(_ca, arguments...)
......@@ -144,17 +160,17 @@ func (_m *ShellWriter) Print(fmt string, arguments ...interface{}) {
}
// RmDir provides a mock function with given fields: path
func (_m *ShellWriter) RmDir(path string) {
func (_m *MockShellWriter) RmDir(path string) {
_m.Called(path)
}
// RmFile provides a mock function with given fields: path
func (_m *ShellWriter) RmFile(path string) {
func (_m *MockShellWriter) RmFile(path string) {
_m.Called(path)
}
// TmpFile provides a mock function with given fields: name
func (_m *ShellWriter) TmpFile(name string) string {
func (_m *MockShellWriter) TmpFile(name string) string {
ret := _m.Called(name)
var r0 string
......@@ -168,12 +184,12 @@ func (_m *ShellWriter) TmpFile(name string) string {
}
// Variable provides a mock function with given fields: variable
func (_m *ShellWriter) Variable(variable common.JobVariable) {
func (_m *MockShellWriter) Variable(variable common.JobVariable) {
_m.Called(variable)
}
// Warning provides a mock function with given fields: fmt, arguments
func (_m *ShellWriter) Warning(fmt string, arguments ...interface{}) {
func (_m *MockShellWriter) Warning(fmt string, arguments ...interface{}) {
var _ca []interface{}
_ca = append(_ca, fmt)
_ca = append(_ca, arguments...)
......
......@@ -93,6 +93,10 @@ func (b *PsWriter) TmpFile(name string) string {
return helpers.ToBackslash(filePath)
}
func (b *PsWriter) EnvVariableKey(name string) string {
return fmt.Sprintf("$%s", name)
}
func (b *PsWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.TmpFile(variable.Key)
......
......@@ -3,6 +3,7 @@ package shells
import "gitlab.com/gitlab-org/gitlab-runner/common"
type ShellWriter interface {
EnvVariableKey(name string) string
Variable(variable common.JobVariable)
Command(command string, arguments ...string)
Line(text 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