Refactor slightly ./shells/shellstest

parent 3fff1dcf
Pipeline #50889661 passed with stages
in 162 minutes and 20 seconds
......@@ -85,6 +85,20 @@ func (_m *MockShellWriter) Error(fmt string, arguments ...interface{}) {
_m.Called(_ca...)
}
// Finish provides a mock function with given fields: trace
func (_m *MockShellWriter) Finish(trace bool) string {
ret := _m.Called(trace)
var r0 string
if rf, ok := ret.Get(0).(func(bool) string); ok {
r0 = rf(trace)
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// IfCmd provides a mock function with given fields: cmd, arguments
func (_m *MockShellWriter) IfCmd(cmd string, arguments ...string) {
_va := make([]interface{}, len(arguments))
......
......@@ -30,4 +30,6 @@ type ShellWriter interface {
Warning(fmt string, arguments ...interface{})
Error(fmt string, arguments ...interface{})
EmptyLine()
Finish(trace bool) string
}
......@@ -11,10 +11,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-runner/shells"
"gitlab.com/gitlab-org/gitlab-runner/shells/shellstest"
)
func runShell(t *testing.T, shell, cwd string, writer shellstest.ShellWriter) {
func runShell(t *testing.T, shell, cwd string, writer shells.ShellWriter) {
var extension string
var cmdArgs []string
......@@ -55,7 +56,7 @@ func TestMkDir(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
shellstest.OnEachShellWithWriter(t, func(t *testing.T, shell string, writer shellstest.ShellWriter) {
shellstest.OnEachShellWithWriter(t, func(t *testing.T, shell string, writer shells.ShellWriter) {
testTmpDir := writer.MkTmpDir(shell + "-mkdir-test")
writer.Cd(testTmpDir)
writer.MkDir(TestPath)
......@@ -76,7 +77,7 @@ func TestRmFile(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
shellstest.OnEachShellWithWriter(t, func(t *testing.T, shell string, writer shellstest.ShellWriter) {
shellstest.OnEachShellWithWriter(t, func(t *testing.T, shell string, writer shells.ShellWriter) {
tmpFile := path.Join(tmpDir, TestPath)
err = ioutil.WriteFile(tmpFile, []byte{}, 0600)
require.NoError(t, err)
......
package shellstest
import "gitlab.com/gitlab-org/gitlab-runner/shells"
type ShellWriter interface {
shells.ShellWriter
Finish(trace bool) string
}
type ShellWriterFactory func() ShellWriter
......@@ -9,6 +9,8 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/shells"
)
type shellWriterFactory func() shells.ShellWriter
func OnEachShell(t *testing.T, f func(t *testing.T, shell string)) {
shells := []string{"bash", "cmd", "powershell"}
......@@ -24,15 +26,15 @@ func OnEachShell(t *testing.T, f func(t *testing.T, shell string)) {
}
}
func OnEachShellWithWriter(t *testing.T, f func(t *testing.T, shell string, writer ShellWriter)) {
writers := map[string]ShellWriterFactory{
"bash": func() ShellWriter {
func OnEachShellWithWriter(t *testing.T, f func(t *testing.T, shell string, writer shells.ShellWriter)) {
writers := map[string]shellWriterFactory{
"bash": func() shells.ShellWriter {
return &shells.BashWriter{}
},
"cmd": func() ShellWriter {
"cmd": func() shells.ShellWriter {
return &shells.CmdWriter{}
},
"powershell": func() ShellWriter {
"powershell": func() shells.ShellWriter {
return &shells.PsWriter{}
},
}
......
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