1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/integration/integration_mta_build_test.go
Florian Wilhelm 219327a427
Rewrite mta IT using docker cli (#1819)
This change addresses some issues of the testcontainer based testing approach (much repeated code, API not on the right abstraction level). It introduces new methods that make use of the docker cli, and rewrites the mta tests using this method.


Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
2020-07-20 18:07:08 +02:00

83 lines
3.0 KiB
Go

// +build integration
// can be execute with go test -tags=integration ./integration/...
package main
import (
"testing"
)
func TestMavenProject(t *testing.T) {
t.Parallel()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "maven:3-openjdk-8-slim",
User: "root",
TestDir: []string{"testdata", "TestMtaIntegration", "maven"},
Mounts: map[string]string{},
Setup: []string{
"apt-get -yqq update; apt-get -yqq install make",
"curl -OL https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.0.14/cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"tar xzf cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"mv mbt /usr/bin",
"curl -sL https://deb.nodesource.com/setup_12.x | bash -",
"apt-get install -yqq nodejs",
},
})
err := container.whenRunningPiperCommand("mtaBuild", "--installArtifacts", "--m2Path=mym2")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "Installing /project/.flattened-pom.xml to /project/mym2/mygroup/mymvn/1.0-SNAPSHOT/mymvn-1.0-SNAPSHOT.pom")
container.assertHasOutput(t, "Installing /project/app/target/mymvn-app-1.0-SNAPSHOT.war to /project/mym2/mygroup/mymvn-app/1.0-SNAPSHOT/mymvn-app-1.0-SNAPSHOT.war")
container.assertHasOutput(t, "Installing /project/app/target/mymvn-app-1.0-SNAPSHOT-classes.jar to /project/mym2/mygroup/mymvn-app/1.0-SNAPSHOT/mymvn-app-1.0-SNAPSHOT-classes.jar")
container.assertHasOutput(t, "added 2 packages from 3 contributors and audited 2 packages in")
}
func TestNPMProject(t *testing.T) {
t.Parallel()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "node:12",
User: "root",
TestDir: []string{"testdata", "TestMtaIntegration", "npm"},
Mounts: map[string]string{},
Setup: []string{
"apt-get -yqq update; apt-get -yqq install make",
"curl -OL https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.0.14/cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"tar xzf cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"mv mbt /usr/bin",
},
})
err := container.whenRunningPiperCommand("mtaBuild", "")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "INFO the MTA archive generated at: test-mta-js.mtar")
}
func TestNPMProjectInstallsDevDependencies(t *testing.T) {
t.Parallel()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "node:12",
User: "root",
TestDir: []string{"testdata", "TestMtaIntegration", "npm-install-dev-dependencies"},
Mounts: map[string]string{},
Setup: []string{
"apt-get -yqq update; apt-get -yqq install make",
"curl -OL https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.0.14/cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"tar xzf cloud-mta-build-tool_1.0.14_Linux_amd64.tar.gz",
"mv mbt /usr/bin",
},
})
err := container.whenRunningPiperCommand("mtaBuild", "--installArtifacts")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "added 2 packages in")
}