Skip to content

Commit

Permalink
avoiding hardcoded logs on integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas authored and mhdawson committed Sep 1, 2023
1 parent 1a1da35 commit 7f1f65f
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 96 deletions.
4 changes: 2 additions & 2 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestIntegration(t *testing.T) {
Expect(err).NotTo(HaveOccurred())
Expect(file.Close()).To(Succeed())

// settings.Buildpack.ID = "paketo-buildpacks/node-engine"
// settings.Buildpack.Name = "Paketo Buildpack for Node Engine"
settings.Buildpack.ID = "paketo-buildpacks/node-engine"
settings.Buildpack.Name = "Paketo Buildpack for Node Engine"

file, err = os.Open("../integration.json")
Expect(err).NotTo(HaveOccurred())
Expand Down
5 changes: 3 additions & 2 deletions integration/openssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
Expand Down Expand Up @@ -88,7 +89,7 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {
Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))
Expand Down Expand Up @@ -132,7 +133,7 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {
Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))
Expand Down
4 changes: 2 additions & 2 deletions integration/optimize_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
Expand Down Expand Up @@ -75,11 +76,10 @@ func testOptimizeMemory(t *testing.T, context spec.G, it spec.S) {

Eventually(container).Should(Serve(ContainSubstring("NodeOptions: --no-warnings --max_old_space_size=96")).OnPort(8080))

fmt.Println(logs)
Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] OPTIMIZE_MEMORY -> "true"`,
Expand Down
6 changes: 3 additions & 3 deletions integration/project_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func testProjectPath(t *testing.T, context spec.G, it spec.S) {
" <unknown> -> \"\""))

Expect(logs).To(ContainLines(
" Selected Node Engine Major version 16",
"===> RESTORING",
"===> EXTENDING (BUILD)"))
" Selected Node Engine Major version 16"))
Expect(logs).To(ContainLines("===> RESTORING"))
Expect(logs).To(ContainLines("===> EXTENDING (BUILD)"))

Expect(logs).To(ContainLines("[extender (build)] Enabling module streams:",
"[extender (build)] nodejs:16"))
Expand Down
12 changes: 6 additions & 6 deletions integration/provides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
Expand Down Expand Up @@ -70,10 +71,9 @@ func testProvides(t *testing.T, context spec.G, it spec.S) {
" Resolving Node Engine version",
" Candidate version sources (in priority order):",
" <unknown> -> \"\""))
Expect(logs).To(ContainLines(
" Selected Node Engine Major version 18",
"===> RESTORING",
"===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines(" Selected Node Engine Major version 18"))
Expect(logs).To(ContainLines("===> RESTORING"))
Expect(logs).To(ContainLines("===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines(
"[extender (build)] Enabling module streams:",
"[extender (build)] nodejs:18"))
Expand All @@ -84,15 +84,15 @@ func testProvides(t *testing.T, context spec.G, it spec.S) {
Expect(logs).To(ContainLines(
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))
Expand Down
162 changes: 81 additions & 81 deletions integration/simple_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
Expand Down Expand Up @@ -89,9 +90,9 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
" <unknown> -> \"\"",
))
Expect(logs).To(ContainLines(
" Selected Node Engine Major version 18",
"===> RESTORING",
"===> EXTENDING (BUILD)"))
" Selected Node Engine Major version 18"))
Expect(logs).To(ContainLines("===> RESTORING"))
Expect(logs).To(ContainLines("===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines(
"[extender (build)] Enabling module streams:",
"[extender (build)] nodejs:18"))
Expand All @@ -100,25 +101,25 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
// therefore there are no available logs to test/validate

Expect(logs).To(ContainLines(
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
))

container, err = docker.Container.Run.
Expand All @@ -138,11 +139,11 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
Expect(string(content)).To(ContainSubstring("hello world"))

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
ContainSubstring("NODE_ENV=production"),
ContainSubstring("NODE_ENV=production"),
)
})
})
Expand Down Expand Up @@ -177,25 +178,25 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainLines(
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
))

container, err = docker.Container.Run.
Expand All @@ -215,14 +216,14 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
Expect(string(content)).To(ContainSubstring("hello world"))

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
And(
ContainSubstring("ENV=production"),
ContainSubstring("VERBOSE=false"),
),
And(
ContainSubstring("ENV=production"),
ContainSubstring("VERBOSE=false"),
),
)
})
})
Expand Down Expand Up @@ -261,11 +262,11 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
" Resolving Node Engine version",
" Candidate version sources (in priority order):",
" .node-version -> \"16.*\"",
" <unknown> -> \"\"",
"",
" Selected Node Engine Major version 16",
"===> RESTORING",
"===> EXTENDING (BUILD)"))
" <unknown> -> \"\""))
Expect(logs).To(ContainLines(
" Selected Node Engine Major version 16"))
Expect(logs).To(ContainLines("===> RESTORING"))
Expect(logs).To(ContainLines("===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines("[extender (build)] Enabling module streams:",
"[extender (build)] nodejs:16"))

Expand All @@ -274,24 +275,24 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {

Expect(logs).To(ContainLines(
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
))

container, err = docker.Container.Run.
Expand All @@ -311,11 +312,11 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
Expect(string(content)).To(ContainSubstring("hello world"))

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
ContainSubstring("NODE_ENV=production"),
ContainSubstring("NODE_ENV=production"),
)
})
})
Expand Down Expand Up @@ -356,36 +357,35 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
" .nvmrc -> \"16.*\"",
" <unknown> -> \"\"",
))
Expect(logs).To(ContainLines(
" Selected Node Engine Major version 16",
"===> RESTORING",
"===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines("[extender (build)] Enabling module streams:",
"[extender (build)] nodejs:16"))
Expect(logs).To(ContainLines(" Selected Node Engine Major version 16"))
Expect(logs).To(ContainLines("===> RESTORING"))
Expect(logs).To(ContainLines("===> EXTENDING (BUILD)"))
Expect(logs).To(ContainLines("[extender (build)] Enabling module streams:"))
Expect(logs).To(ContainLines("[extender (build)] nodejs:16"))

// SBOM is not supported at the moment from UBI image
// therefore there are no available logs to test/validate

Expect(logs).To(ContainLines(
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
"[extender (build)] Configuring build environment",
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
`[extender (build)] NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"`,
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
`[extender (build)] Configuring launch environment`,
`[extender (build)] NODE_ENV -> "production"`,
fmt.Sprintf(`[extender (build)] NODE_HOME -> "/layers/%s/node"`, strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
`[extender (build)] NODE_OPTIONS -> "--use-openssl-ca"`,
`[extender (build)] NODE_VERBOSE -> "false"`,
))

Expect(logs).To(ContainLines(
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
"[extender (build)] Writing exec.d/0-optimize-memory",
"[extender (build)] Calculates available memory based on container limits at launch time.",
"[extender (build)] Made available in the MEMORY_AVAILABLE environment variable.",
))

container, err = docker.Container.Run.
Expand All @@ -405,11 +405,11 @@ func testSimple(t *testing.T, context spec.G, it spec.S) {
Expect(string(content)).To(ContainSubstring("hello world"))

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
ContainSubstring("NODE_ENV=production"),
ContainSubstring("NODE_ENV=production"),
)
})
})
Expand Down

0 comments on commit 7f1f65f

Please sign in to comment.