You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-05 00:59:01 +02:00
Maven Build Integration Test (#1820)
Follow up for #1819, adding a new IT for `mavenBuild` which had none so far.
This commit is contained in:
@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/SAP/jenkins-library/pkg/command"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"io/ioutil"
|
||||
@ -66,30 +67,45 @@ func givenThisContainer(t *testing.T, bundle IntegrationTestDockerExecRunnerBund
|
||||
t.Fatal("Could not locate piper binary to test")
|
||||
}
|
||||
|
||||
projectDir := path.Join(wd, path.Join(bundle.TestDir...))
|
||||
|
||||
// 1. Copy test files to a temp dir in order to avoid non-repeatable test executions because of changed state
|
||||
// 2. Don't remove the temp dir to allow investigation of failed tests. Maybe add an option for cleaning it later?
|
||||
tempDir, err := ioutil.TempDir("", "piper-integration-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
params := []string{"run", "--detach", "-v", localPiper + ":/piper", "--name=" + testRunner.ContainerName}
|
||||
if testRunner.User != "" {
|
||||
params = append(params, fmt.Sprintf("--user=%s", testRunner.User))
|
||||
}
|
||||
if len(bundle.TestDir) > 0 {
|
||||
projectDir := path.Join(wd, path.Join(bundle.TestDir...))
|
||||
// 1. Copy test files to a temp dir in order to avoid non-repeatable test executions because of changed state
|
||||
// 2. Don't remove the temp dir to allow investigation of failed tests. Maybe add an option for cleaning it later?
|
||||
tempDir, err := ioutil.TempDir("", "piper-integration-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = copyDir(projectDir, tempDir)
|
||||
if err != nil {
|
||||
t.Fatalf("")
|
||||
err = copyDir(projectDir, tempDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to copy files from %s into %s", projectDir, tempDir)
|
||||
}
|
||||
params = append(params, "-v", fmt.Sprintf("%s:/project", tempDir))
|
||||
}
|
||||
if len(testRunner.Environment) > 0 {
|
||||
for envVarName, envVarValue := range testRunner.Environment {
|
||||
params = append(params, "--env", fmt.Sprintf("%s='%s'", envVarName, envVarValue))
|
||||
}
|
||||
}
|
||||
params = append(params, testRunner.Image, "sleep", "2000")
|
||||
|
||||
//todo mounts
|
||||
//todo env (secrets)
|
||||
err = testRunner.Runner.RunExecutable("docker", "run", "-d", "-u="+testRunner.User,
|
||||
"-v", localPiper+":/piper", "-v", tempDir+":/project",
|
||||
"--name="+testRunner.ContainerName,
|
||||
testRunner.Image,
|
||||
"sleep", "2000")
|
||||
err := testRunner.Runner.RunExecutable("docker", params...)
|
||||
if err != nil {
|
||||
t.Fatalf("Starting test container has failed %s", err)
|
||||
}
|
||||
|
||||
if len(bundle.TestDir) > 0 {
|
||||
err = testRunner.Runner.RunExecutable("docker", "exec", "-u=root", testRunner.ContainerName, "chown", "-R", testRunner.User, "/project")
|
||||
if err != nil {
|
||||
t.Fatalf("Chown /project has failed %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, scriptLine := range testRunner.Setup {
|
||||
err := testRunner.Runner.RunExecutable("docker", "exec", testRunner.ContainerName, "/bin/bash", "-c", scriptLine)
|
||||
if err != nil {
|
||||
@ -101,7 +117,7 @@ func givenThisContainer(t *testing.T, bundle IntegrationTestDockerExecRunnerBund
|
||||
if err != nil {
|
||||
t.Fatalf("Copying command wrapper to container has failed %s", err)
|
||||
}
|
||||
err = testRunner.Runner.RunExecutable("docker", "exec", testRunner.ContainerName, "chmod", "+x", "/piper-wrapper")
|
||||
err = testRunner.Runner.RunExecutable("docker", "exec", "-u=root", testRunner.ContainerName, "chmod", "+x", "/piper-wrapper")
|
||||
if err != nil {
|
||||
t.Fatalf("Making command wrapper in container executable has failed %s", err)
|
||||
}
|
||||
@ -127,3 +143,10 @@ func (d *IntegrationTestDockerExecRunner) assertHasOutput(t *testing.T, want str
|
||||
t.Fatalf("Assertion has failed. Expected output %s in command output.\n%s", want, buffer.String())
|
||||
}
|
||||
}
|
||||
|
||||
func (d *IntegrationTestDockerExecRunner) assertHasFile(t *testing.T, want string) {
|
||||
err := d.Runner.RunExecutable("docker", "exec", d.ContainerName, "stat", want)
|
||||
if err != nil {
|
||||
t.Fatalf("Assertion has failed. Expected file %s to exist in container. %s", want, err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user