From 777e343a49fa7a926b08fb8459b2807696c19697 Mon Sep 17 00:00:00 2001 From: Anthony Dahanne Date: Thu, 21 Sep 2023 16:49:18 -0400 Subject: [PATCH] Make Java Smoke Test PR workflow generic * so that it can be used for every Java samples --- .../workflows/test-pull-request-java-akka.yml | 29 ----- .github/workflows/test-pull-request-java.yml | 117 ++++++++++-------- java/akka/smoke_test/akka_test.go | 6 +- .../smoke_test/application_insights_test.go | 6 +- java/{ => aspectj/smoke_test}/aspectj_test.go | 15 ++- java/{ => deps/smoke_test}/deps_test.go | 15 ++- .../smoke_test}/dist_zip_test.go | 15 ++- java/{ => gradle/smoke_test}/gradle_test.go | 15 ++- java/{ => jar/smoke_test}/jar_test.go | 13 +- java/java-node/gradle_node_test.go | 2 - java/java-node/maven_node_test.go | 2 - java/java_test.go | 13 -- java/{ => kotlin/smoke_test}/kotlin_test.go | 15 ++- .../smoke_test}/leiningen_test.go | 15 ++- java/{ => maven/smoke_test}/maven_test.go | 15 ++- .../java_native_image_gradle_test.go | 2 - .../java_native_image_maven_test.go | 2 - ...va_native_image_public_static_main_test.go | 2 - .../java_native_image_quarkus_native_test.go | 2 - .../smoke_test}/opentelemetry_test.go | 13 +- .../smoke_test}/tools_build_test.go | 15 ++- java/{ => war/smoke_test}/war_test.go | 15 ++- 22 files changed, 180 insertions(+), 164 deletions(-) delete mode 100644 .github/workflows/test-pull-request-java-akka.yml rename java/{ => aspectj/smoke_test}/aspectj_test.go (89%) rename java/{ => deps/smoke_test}/deps_test.go (89%) rename java/{ => dist-zip/smoke_test}/dist_zip_test.go (90%) rename java/{ => gradle/smoke_test}/gradle_test.go (89%) rename java/{ => jar/smoke_test}/jar_test.go (89%) delete mode 100644 java/java_test.go rename java/{ => kotlin/smoke_test}/kotlin_test.go (89%) rename java/{ => leiningen/smoke_test}/leiningen_test.go (89%) rename java/{ => maven/smoke_test}/maven_test.go (89%) rename java/{ => opentelemetry/smoke_test}/opentelemetry_test.go (90%) rename java/{ => tools-build/smoke_test}/tools_build_test.go (89%) rename java/{ => war/smoke_test}/war_test.go (89%) diff --git a/.github/workflows/test-pull-request-java-akka.yml b/.github/workflows/test-pull-request-java-akka.yml deleted file mode 100644 index e97c201b..00000000 --- a/.github/workflows/test-pull-request-java-akka.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Test Pull Request (Akka) - -on: - merge_group: - pull_request: - branches: - - main - paths: - - java/akka/** - -jobs: - smoke: - name: Smoke Tests - runs-on: ubuntu-latest - steps: - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: 1.18.x - - - name: Checkout - uses: actions/checkout@v4 - - - name: Test Java Samples - run: | - ./scripts/smoke.sh --suite java/akka/smoke_test \ - --builder paketobuildpacks/builder:full \ - --builder paketobuildpacks/builder:base \ - --builder paketobuildpacks/builder:tiny diff --git a/.github/workflows/test-pull-request-java.yml b/.github/workflows/test-pull-request-java.yml index 5c180c4f..16532f43 100644 --- a/.github/workflows/test-pull-request-java.yml +++ b/.github/workflows/test-pull-request-java.yml @@ -1,63 +1,78 @@ -name: Test Pull Request (Java) +name: Smoke Test Pull Request (Java) on: merge_group: pull_request: branches: - - main + - main paths: - - 'java/**' - - '!java/native-image/**' - - '!java/java-node/**' + - 'java/**' jobs: + prepare: + name: Prepare + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.paths.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Discover changed paths + id: paths + run: | + env + # see: https://stackoverflow.com/a/8721550/24069 for usage of paste + changed_java_folders=$( git diff --name-only --merge-base origin/$GITHUB_BASE_REF $GITHUB_SHA | xargs -n 1 dirname | sort -k 2 | uniq | grep -v "^\." ) + + smoke_test_folders="" + while read -r changed_folder + do + echo "working on $changed_folder" + smoke_test="" + current_folder=$changed_folder + while [ -z "$smoke_test" ] && [ "$current_folder" != "." ] + do + echo "--smoke_test is $smoke_test" + echo "--current_folder is $current_folder" + if [[ -s $current_folder/smoke_test ]]; then + smoke_test="$current_folder/smoke_test" + else + current_folder=$(dirname $current_folder) + fi + done + if [ "$current_folder" != "." ]; then + smoke_test_folders="$smoke_test_folders\"$smoke_test\"\n" + fi + done <<<"$changed_java_folders" + + smoke_test_folders=$( echo -e $smoke_test_folders | uniq | grep "\S" | paste -s -d, -) + + echo "These are the Java folders where we found changes for this PR : $changed_java_folders" >> $GITHUB_STEP_SUMMARY + echo "These are the Java folders where we found changes AND the presence of smoke tests for this PR : $smoke_test_folders" >> $GITHUB_STEP_SUMMARY + echo "matrix={\"java_sample_folder\":[$smoke_test_folders]}" >> $GITHUB_OUTPUT + echo "This is how the matrix will look like: $(cat $GITHUB_OUTPUT)" + smoke: + needs: prepare name: Smoke Tests runs-on: ubuntu-latest + strategy: + matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }} + steps: - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: 1.18.x - - - name: Checkout - uses: actions/checkout@v4 - - - name: Cache local Gradle repository - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('java/**/*.gradle*', 'java/**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Cache local Maven repository - uses: actions/cache@v3 - with: - path: | - ~/.m2/repository - ~/.m2/wrapper - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', 'java/**/maven-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Setup Directories - run: | - #!/usr/bin/env bash - set -euo pipefail - - mkdir -p ~/.m2/repository - mkdir -p ~/.m2/repository/wrapper/dists - mkdir -p ~/.gradle/caches - mkdir -p ~/.gradle/wrapper/dists - chmod -R 775 ~/.m2 - chmod -R 775 ~/.gradle - - - name: Test Java Samples - run: | - ./scripts/smoke.sh --suite java \ - --builder paketobuildpacks/builder:full \ - --builder paketobuildpacks/builder:base \ - --builder paketobuildpacks/builder:tiny + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.20.x + + - name: Checkout + uses: actions/checkout@v4 + + - name: Smoke Test Java samples + run: | + echo "About to run the smoke test script against this suite folder: ${{ matrix.java_sample_folder }}/smoke_test" + ./scripts/smoke.sh --suite ${{ matrix.java_sample_folder }} \ + --builder paketobuildpacks/builder:base \ + --builder paketobuildpacks/builder:tiny diff --git a/java/akka/smoke_test/akka_test.go b/java/akka/smoke_test/akka_test.go index ebcf0b96..fd5997ef 100644 --- a/java/akka/smoke_test/akka_test.go +++ b/java/akka/smoke_test/akka_test.go @@ -46,7 +46,6 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -81,7 +80,7 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err.Error()).To(ContainSubstring("failed to remove docker image: exit status 1: Error")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -96,14 +95,13 @@ func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { } var err error - source, err = occam.Source(filepath.Join("../../", "akka")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/application-insights/smoke_test/application_insights_test.go b/java/application-insights/smoke_test/application_insights_test.go index 5449fa44..0b99de3f 100644 --- a/java/application-insights/smoke_test/application_insights_test.go +++ b/java/application-insights/smoke_test/application_insights_test.go @@ -45,7 +45,6 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -80,7 +79,7 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -91,14 +90,13 @@ func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G context("app uses application insights", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "application-insights")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/aspectj_test.go b/java/aspectj/smoke_test/aspectj_test.go similarity index 89% rename from java/aspectj_test.go rename to java/aspectj/smoke_test/aspectj_test.go index b6c8101d..5f5a8813 100644 --- a/java/aspectj_test.go +++ b/java/aspectj/smoke_test/aspectj_test.go @@ -1,7 +1,9 @@ -package java_test +package aspectj_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestAspectJ(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,14 +89,13 @@ func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses aspectj", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "aspectj")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/deps_test.go b/java/deps/smoke_test/deps_test.go similarity index 89% rename from java/deps_test.go rename to java/deps/smoke_test/deps_test.go index 2991483d..46748d1b 100644 --- a/java/deps_test.go +++ b/java/deps/smoke_test/deps_test.go @@ -1,7 +1,9 @@ -package java_test +package deps_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestDeps(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,7 +89,7 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses clojure tools with deps", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "deps")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -93,7 +99,6 @@ func testDepsWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "JAVA_TOOL_OPTIONS": "-XX:MaxMetaspaceSize=100M", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/dist_zip_test.go b/java/dist-zip/smoke_test/dist_zip_test.go similarity index 90% rename from java/dist_zip_test.go rename to java/dist-zip/smoke_test/dist_zip_test.go index d754cd20..9664ffd9 100644 --- a/java/dist_zip_test.go +++ b/java/dist-zip/smoke_test/dist_zip_test.go @@ -1,7 +1,9 @@ -package java_test +package dist_zip_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "strings" @@ -16,6 +18,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestDistZip(t *testing.T) { Expect := NewWithT(t).Expect @@ -38,7 +45,6 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -73,7 +79,7 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -88,7 +94,7 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { } var err error - source, err = occam.Source(filepath.Join("../java", "dist-zip")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -99,7 +105,6 @@ func testDistZipWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "BP_GRADLE_BUILD_ARGUMENTS": "--no-daemon -x test bootDistZip", "BP_GRADLE_BUILT_ARTIFACT": "build/distributions/*.zip"}). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/gradle_test.go b/java/gradle/smoke_test/gradle_test.go similarity index 89% rename from java/gradle_test.go rename to java/gradle/smoke_test/gradle_test.go index 5a38e6cb..34e21f3a 100644 --- a/java/gradle_test.go +++ b/java/gradle/smoke_test/gradle_test.go @@ -1,7 +1,9 @@ -package java_test +package gradle_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestGradle(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,7 +89,7 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses gradle", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "gradle")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -94,7 +100,6 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "BP_GRADLE_BUILT_ARTIFACT": "build/libs/*-SNAPSHOT.jar", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/jar_test.go b/java/jar/smoke_test/jar_test.go similarity index 89% rename from java/jar_test.go rename to java/jar/smoke_test/jar_test.go index aec51000..3a53ba89 100644 --- a/java/jar_test.go +++ b/java/jar/smoke_test/jar_test.go @@ -1,7 +1,9 @@ -package java_test +package jar_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestJar(t *testing.T) { Expect := NewWithT(t).Expect @@ -71,7 +78,7 @@ func testJarWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -82,7 +89,7 @@ func testJarWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses jar", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "jar")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer diff --git a/java/java-node/gradle_node_test.go b/java/java-node/gradle_node_test.go index 310f2613..280ab011 100644 --- a/java/java-node/gradle_node_test.go +++ b/java/java-node/gradle_node_test.go @@ -45,7 +45,6 @@ func testGradleNodeWithBuilder(builder string) func(*testing.T, spec.G, spec.S) pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -98,7 +97,6 @@ func testGradleNodeWithBuilder(builder string) func(*testing.T, spec.G, spec.S) image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)). WithGID("123"). WithEnv(map[string]string{ "BP_JVM_VERSION": "17", diff --git a/java/java-node/maven_node_test.go b/java/java-node/maven_node_test.go index da22d6e6..a59c026c 100644 --- a/java/java-node/maven_node_test.go +++ b/java/java-node/maven_node_test.go @@ -37,7 +37,6 @@ func testMavenNodeWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -90,7 +89,6 @@ func testMavenNodeWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). WithEnv(map[string]string{ "BP_JVM_VERSION": "17", diff --git a/java/java_test.go b/java/java_test.go deleted file mode 100644 index b81a0b33..00000000 --- a/java/java_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package java_test - -import ( - "flag" - - "github.com/paketo-buildpacks/samples/tests" -) - -var builders tests.BuilderFlags - -func init() { - flag.Var(&builders, "name", "the name a builder to test with") -} diff --git a/java/kotlin_test.go b/java/kotlin/smoke_test/kotlin_test.go similarity index 89% rename from java/kotlin_test.go rename to java/kotlin/smoke_test/kotlin_test.go index 548e6165..3167cfc8 100644 --- a/java/kotlin_test.go +++ b/java/kotlin/smoke_test/kotlin_test.go @@ -1,7 +1,9 @@ -package java_test +package kotlin_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestKotlin(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testKotlinWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testKotlinWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,7 +89,7 @@ func testKotlinWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses kotlin", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "kotlin")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -93,7 +99,6 @@ func testKotlinWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "BP_GRADLE_BUILT_ARTIFACT": "build/libs/*-SNAPSHOT.jar", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/leiningen_test.go b/java/leiningen/smoke_test/leiningen_test.go similarity index 89% rename from java/leiningen_test.go rename to java/leiningen/smoke_test/leiningen_test.go index 4c634712..1481e846 100644 --- a/java/leiningen_test.go +++ b/java/leiningen/smoke_test/leiningen_test.go @@ -1,7 +1,9 @@ -package java_test +package leiningen_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestLeiningen(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testLeiningenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testLeiningenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,7 +89,7 @@ func testLeiningenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses leiningen", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "leiningen")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -93,7 +99,6 @@ func testLeiningenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "JAVA_TOOL_OPTIONS": "-XX:MaxMetaspaceSize=100M", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/maven_test.go b/java/maven/smoke_test/maven_test.go similarity index 89% rename from java/maven_test.go rename to java/maven/smoke_test/maven_test.go index 6befe378..fc9e236c 100644 --- a/java/maven_test.go +++ b/java/maven/smoke_test/maven_test.go @@ -1,7 +1,9 @@ -package java_test +package maven_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestMaven(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testMavenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testMavenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,14 +89,13 @@ func testMavenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses maven", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "maven")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). WithEnv(map[string]string{"BP_JVM_VERSION": "17"}). Execute(name, source) diff --git a/java/native-image/java_native_image_gradle_test.go b/java/native-image/java_native_image_gradle_test.go index 1a18375a..396c8d1f 100644 --- a/java/native-image/java_native_image_gradle_test.go +++ b/java/native-image/java_native_image_gradle_test.go @@ -45,7 +45,6 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -87,7 +86,6 @@ func testGradleWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { WithEnv(map[string]string{ "BP_NATIVE_IMAGE": "true"}). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.gradle:/home/cnb/.gradle:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/native-image/java_native_image_maven_test.go b/java/native-image/java_native_image_maven_test.go index 2c7953ed..8f3a80d8 100644 --- a/java/native-image/java_native_image_maven_test.go +++ b/java/native-image/java_native_image_maven_test.go @@ -37,7 +37,6 @@ func testMavenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -81,7 +80,6 @@ func testMavenWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "BP_MAVEN_BUILD_ARGUMENTS": "-Dmaven.test.skip=true --no-transfer-progress -Pnative package", "BP_JVM_VERSION": "17"}). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/native-image/java_native_image_public_static_main_test.go b/java/native-image/java_native_image_public_static_main_test.go index ac0eb51c..927a1b86 100644 --- a/java/native-image/java_native_image_public_static_main_test.go +++ b/java/native-image/java_native_image_public_static_main_test.go @@ -37,7 +37,6 @@ func testPublicStaticMainWithBuilder(builder string) func(*testing.T, spec.G, sp pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -78,7 +77,6 @@ func testPublicStaticMainWithBuilder(builder string) func(*testing.T, spec.G, sp WithPullPolicy("never"). WithEnv(map[string]string{"BP_NATIVE_IMAGE": "true"}). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/native-image/java_native_image_quarkus_native_test.go b/java/native-image/java_native_image_quarkus_native_test.go index 9af1902e..ea33eed8 100644 --- a/java/native-image/java_native_image_quarkus_native_test.go +++ b/java/native-image/java_native_image_quarkus_native_test.go @@ -37,7 +37,6 @@ func testQuarkusWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -84,7 +83,6 @@ func testQuarkusWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { "BP_NATIVE_IMAGE_BUILT_ARTIFACT": "native-sources/getting-started-*-runner.jar", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/opentelemetry_test.go b/java/opentelemetry/smoke_test/opentelemetry_test.go similarity index 90% rename from java/opentelemetry_test.go rename to java/opentelemetry/smoke_test/opentelemetry_test.go index 14ea0df8..fd01be68 100644 --- a/java/opentelemetry_test.go +++ b/java/opentelemetry/smoke_test/opentelemetry_test.go @@ -1,7 +1,9 @@ -package java_test +package opentelemetry_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestOpentelemetry(t *testing.T) { Expect := NewWithT(t).Expect @@ -71,7 +78,7 @@ func testOpentelemetryWithBuilder(builder string) func(*testing.T, spec.G, spec. err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -82,7 +89,7 @@ func testOpentelemetryWithBuilder(builder string) func(*testing.T, spec.G, spec. context("app uses opentelemetry", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "opentelemetry")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer diff --git a/java/tools_build_test.go b/java/tools-build/smoke_test/tools_build_test.go similarity index 89% rename from java/tools_build_test.go rename to java/tools-build/smoke_test/tools_build_test.go index 3e97c3eb..e79f8086 100644 --- a/java/tools_build_test.go +++ b/java/tools-build/smoke_test/tools_build_test.go @@ -1,7 +1,9 @@ -package java_test +package tools_build_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestToolsBuild(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testToolsBuildWithBuilder(builder string) func(*testing.T, spec.G, spec.S) pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testToolsBuildWithBuilder(builder string) func(*testing.T, spec.G, spec.S) err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,7 +89,7 @@ func testToolsBuildWithBuilder(builder string) func(*testing.T, spec.G, spec.S) context("app uses clojure tools with tools build", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "tools-build")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer @@ -94,7 +100,6 @@ func testToolsBuildWithBuilder(builder string) func(*testing.T, spec.G, spec.S) "JAVA_TOOL_OPTIONS": "-XX:MaxMetaspaceSize=100M", }). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) diff --git a/java/war_test.go b/java/war/smoke_test/war_test.go similarity index 89% rename from java/war_test.go rename to java/war/smoke_test/war_test.go index e8a4a160..ed9887fa 100644 --- a/java/war_test.go +++ b/java/war/smoke_test/war_test.go @@ -1,7 +1,9 @@ -package java_test +package war_test import ( + "flag" "fmt" + "github.com/paketo-buildpacks/samples/tests" "os" "path/filepath" "testing" @@ -15,6 +17,11 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) +var builders tests.BuilderFlags + +func init() { + flag.Var(&builders, "name", "the name a builder to test with") +} func TestWAR(t *testing.T) { Expect := NewWithT(t).Expect @@ -37,7 +44,6 @@ func testWARWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { pack occam.Pack docker occam.Docker - home string = os.Getenv("HOME") ) it.Before(func() { @@ -72,7 +78,7 @@ func testWARWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { err = docker.Image.Remove.Execute(image.ID) if err != nil { - Expect(err).To(MatchError("failed to remove docker image: exit status 1: Error: No such image:")) + Expect(err).To(MatchError(ContainSubstring("failed to remove docker image: exit status 1: Error"))) } else { Expect(err).ToNot(HaveOccurred()) } @@ -83,14 +89,13 @@ func testWARWithBuilder(builder string) func(*testing.T, spec.G, spec.S) { context("app uses war", func() { it("builds successfully", func() { var err error - source, err = occam.Source(filepath.Join("../java", "war")) + source, err = occam.Source(filepath.Join("../")) Expect(err).NotTo(HaveOccurred()) var logs fmt.Stringer image, logs, err = pack.Build. WithPullPolicy("never"). WithBuilder(builder). - WithVolumes(fmt.Sprintf("%s/.m2:/home/cnb/.m2:rw", home)). WithGID("123"). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String)