1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-04-11 11:41:53 +02:00

chore (containerExecuteStructureTests): switch default container (#4288)

This commit is contained in:
Oliver Nocon 2023-03-21 08:06:22 +01:00 committed by GitHub
parent b835498449
commit 7c4262b0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 21 deletions

View File

@ -52,7 +52,7 @@ func findConfigFiles(pattern string, utils containerExecuteStructureTestsUtils)
}
func runContainerExecuteStructureTests(config *containerExecuteStructureTestsOptions, utils containerExecuteStructureTestsUtils) error {
containerStructureTestsExecutable := "container-structure-test"
containerStructureTestsExecutable := "./container-structure-test"
var parameters []string
parameters = append(parameters, "test")
configFiles, err := findConfigFiles(config.TestConfiguration, utils)

View File

@ -189,7 +189,7 @@ func containerExecuteStructureTestsMetadata() config.StepData {
},
},
Containers: []config.Container{
{Image: "ppiper/container-structure-test", Options: []config.Option{{Name: "-u", Value: "0"}, {Name: "--entrypoint", Value: ""}}},
{Image: "gcr.io/gcp-runtimes/container-structure-test:debug", Options: []config.Option{{Name: "-u", Value: "0"}, {Name: "--entrypoint", Value: ""}}},
},
},
}

View File

@ -39,7 +39,6 @@ func newContainerStructureTestsMockUtils() containerStructureTestsMockUtils {
}
func TestRunContainerExecuteStructureTests(t *testing.T) {
t.Run("success case", func(t *testing.T) {
config := &containerExecuteStructureTestsOptions{
PullImage: true,
@ -66,7 +65,7 @@ func TestRunContainerExecuteStructureTests(t *testing.T) {
assert.NoError(t, err)
if assert.Equal(t, 1, len(mockUtils.Calls)) {
assert.Equal(t, "container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, "./container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, expectedParams, mockUtils.Calls[0].Params)
}
})
@ -95,7 +94,7 @@ func TestRunContainerExecuteStructureTests(t *testing.T) {
assert.NoError(t, err)
if assert.Equal(t, 1, len(mockUtils.Calls)) {
assert.Equal(t, "container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, "./container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, expectedParams, mockUtils.Calls[0].Params)
}
})
@ -126,7 +125,7 @@ func TestRunContainerExecuteStructureTests(t *testing.T) {
assert.NoError(t, err)
if assert.Equal(t, 1, len(mockUtils.Calls)) {
assert.Equal(t, "container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, "./container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, expectedParams, mockUtils.Calls[0].Params)
}
GeneralConfig.Verbose = false
@ -158,7 +157,7 @@ func TestRunContainerExecuteStructureTests(t *testing.T) {
assert.NoError(t, err)
if assert.Equal(t, 1, len(mockUtils.Calls)) {
assert.Equal(t, "container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, "./container-structure-test", mockUtils.Calls[0].Exec)
assert.Equal(t, expectedParams, mockUtils.Calls[0].Params)
}
os.Unsetenv("ON_K8S")
@ -180,7 +179,7 @@ func TestRunContainerExecuteStructureTests(t *testing.T) {
// test
err := runContainerExecuteStructureTests(config, &mockUtils)
// assert
assert.EqualError(t, err, "failed to run executable, command: '[container-structure-test test --config config1.yaml --config config2.yaml --driver docker --pull --image reg/image:tag --test-report report.json]', error: container-structure-test run failed: container-structure-test run failed")
assert.EqualError(t, err, "failed to run executable, command: '[./container-structure-test test --config config1.yaml --config config2.yaml --driver docker --pull --image reg/image:tag --test-report report.json]', error: container-structure-test run failed: container-structure-test run failed")
})
t.Run("error case - configuration is missing", func(t *testing.T) {

View File

@ -100,7 +100,6 @@ var ExecCommand = exec.Command
// RunShell runs the specified command on the shell
func (c *Command) RunShell(shell, script string) error {
c.prepareOut()
cmd := ExecCommand(shell)
@ -128,7 +127,6 @@ func (c *Command) RunShell(shell, script string) error {
//
// Thus the executable needs to be on the PATH of the current process and it is not sufficient to alter the PATH on cmd.Env.
func (c *Command) RunExecutable(executable string, params ...string) error {
c.prepareOut()
cmd := ExecCommand(executable, params...)
@ -156,7 +154,6 @@ func (c *Command) RunExecutable(executable string, params ...string) error {
//
// Thus the executable needs to be on the PATH of the current process and it is not sufficient to alter the PATH on cmd.Env.
func (c *Command) RunExecutableInBackground(executable string, params ...string) (Execution, error) {
c.prepareOut()
cmd := ExecCommand(executable, params...)
@ -174,7 +171,6 @@ func (c *Command) RunExecutableInBackground(executable string, params ...string)
}
execution, err := c.startCmd(cmd)
if err != nil {
return nil, errors.Wrapf(err, "starting command '%v' failed", executable)
}
@ -188,7 +184,6 @@ func (c *Command) GetExitCode() int {
}
func appendEnvironment(cmd *exec.Cmd, env []string) {
if len(env) > 0 {
// When cmd.Env is nil the environment variables from the current
@ -215,9 +210,7 @@ func appendEnvironment(cmd *exec.Cmd, env []string) {
}
func (c *Command) startCmd(cmd *exec.Cmd) (*execution, error) {
stdout, stderr, err := cmdPipes(cmd)
if err != nil {
return nil, errors.Wrap(err, "getting command pipes failed")
}
@ -348,7 +341,6 @@ func matchPattern(text, pattern string) bool {
}
func (c *Command) runCmd(cmd *exec.Cmd) error {
execution, err := c.startCmd(cmd)
if err != nil {
return err
@ -376,10 +368,9 @@ func (c *Command) runCmd(cmd *exec.Cmd) error {
}
func (c *Command) prepareOut() {
//ToDo: check use of multiwriter instead to always write into os.Stdout and os.Stdin?
//stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
//stderr := io.MultiWriter(os.Stderr, &stderrBuf)
// ToDo: check use of multiwriter instead to always write into os.Stdout and os.Stdin?
// stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
// stderr := io.MultiWriter(os.Stderr, &stderrBuf)
if c.stdout == nil {
c.stdout = os.Stdout

View File

@ -49,7 +49,7 @@ spec:
- PARAMETERS
default: cst-report.json
containers:
- image: ppiper/container-structure-test
- image: gcr.io/gcp-runtimes/container-structure-test:debug
command:
- /busybox/tail -f /dev/null
shell: /busybox/sh