Skip to content

Commit

Permalink
WIP: move to having a single test suite per application
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Sep 18, 2023
1 parent 1fe7b73 commit 12a0768
Show file tree
Hide file tree
Showing 21 changed files with 2,087 additions and 778 deletions.
118 changes: 118 additions & 0 deletions java/akka_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package java_test

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func TestAkka(t *testing.T) {
Expect := NewWithT(t).Expect

Expect(len(builders)).NotTo(Equal(0))

SetDefaultEventuallyTimeout(60 * time.Second)

suite := spec.New("Java - Akka", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("Akka with %s builder", builder), testAkkaWithBuilder(builder), spec.Sequential())
}
suite.Run(t)
}

func testAkkaWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})

context("detects a Java app", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
err := docker.Container.Remove.Execute(container.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker container: exit status 1: Container name cannot be empty"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

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:"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(os.RemoveAll(source)).To(Succeed())
})

context("app uses akka", func() {
it("builds successfully", func() {
if strings.HasSuffix(builder, "tiny") {
return // this sample requires bash, does not run on tiny
}

var err error
source, err = occam.Source(filepath.Join("../java", "akka"))
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)

Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for CA Certificates")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for BellSoft Liberica")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for SBT")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for DistZip")))

container, err = docker.Container.Run.
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(BeAvailable())
})
})
})
}
}
114 changes: 114 additions & 0 deletions java/application_insights_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package java_test

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func TestApplicationInsights(t *testing.T) {
Expect := NewWithT(t).Expect

Expect(len(builders)).NotTo(Equal(0))

SetDefaultEventuallyTimeout(60 * time.Second)

suite := spec.New("Java - Application Insights", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("Application Insights with %s builder", builder), testApplicationInsightsWithBuilders(builder), spec.Sequential())
}
suite.Run(t)
}

func testApplicationInsightsWithBuilders(builder string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})

context("detects a Java app", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
err := docker.Container.Remove.Execute(container.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker container: exit status 1: Container name cannot be empty"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

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:"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(os.RemoveAll(source)).To(Succeed())
})

context("app uses application insights", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../java", "application-insights"))
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)

Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for CA Certificates")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for BellSoft Liberica")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Maven")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Executable JAR")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Spring Boot")))

container, err = docker.Container.Run.
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("UP")).OnPort(8080).WithEndpoint("/actuator/health"))
})
})
})
}
}
114 changes: 114 additions & 0 deletions java/aspectj_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package java_test

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func TestAspectJ(t *testing.T) {
Expect := NewWithT(t).Expect

Expect(len(builders)).NotTo(Equal(0))

SetDefaultEventuallyTimeout(60 * time.Second)

suite := spec.New("Java - AspectJ", spec.Parallel(), spec.Report(report.Terminal{}))
for _, builder := range builders {
suite(fmt.Sprintf("AspectJ with %s builder", builder), testAspectJWithBuilder(builder), spec.Sequential())
}
suite.Run(t)
}

func testAspectJWithBuilder(builder string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
home string = os.Getenv("HOME")
)

it.Before(func() {
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})

context("detects a Java app", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
err := docker.Container.Remove.Execute(container.ID)
if err != nil {
Expect(err).To(MatchError("failed to remove docker container: exit status 1: Container name cannot be empty"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

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:"))
} else {
Expect(err).ToNot(HaveOccurred())
}

Expect(os.RemoveAll(source)).To(Succeed())
})

context("app uses aspectj", func() {
it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("../java", "aspectj"))
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)

Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for CA Certificates")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for BellSoft Liberica")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Maven")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Executable JAR")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo Buildpack for Spring Boot")))

container, err = docker.Container.Run.
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("UP")).OnPort(8080).WithEndpoint("/actuator/health"))
})
})
})
}
}
Loading

0 comments on commit 12a0768

Please sign in to comment.