Skip to content

Commit

Permalink
update logging integration test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Wigmore authored and thitch97 committed Apr 19, 2023
1 parent fbdddf1 commit defb665
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 57 deletions.
21 changes: 8 additions & 13 deletions install_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,17 +53,15 @@ func (ip YarnInstallProcess) ShouldRun(workingDir string, metadata map[string]in
ip.logger.Break()

buffer := bytes.NewBuffer(nil)
listArgs := []string{"config", "list", "--silent"}
ip.logger.Subprocess("Running 'yarn %s'", strings.Join(listArgs, " "))

err = ip.executable.Execute(pexec.Execution{
Args: listArgs,
Stdout: io.MultiWriter(ip.logger.ActionWriter, buffer),
Stderr: io.MultiWriter(ip.logger.ActionWriter, buffer),
Args: []string{"config", "list", "--silent"},
Stdout: buffer,
Stderr: buffer,
Dir: workingDir,
})
if err != nil {
return true, "", fmt.Errorf("failed to execute yarn config output:\nerror: %s", err)
return true, "", fmt.Errorf("failed to execute yarn config output:\n%s\nerror: %s", buffer.String(), err)
}

nodeEnv := os.Getenv("NODE_ENV")
Expand Down Expand Up @@ -147,18 +144,16 @@ func (ip YarnInstallProcess) Execute(workingDir, modulesLayerPath string, launch
environment = append(environment, fmt.Sprintf("PATH=%s%c%s", os.Getenv("PATH"), os.PathListSeparator, filepath.Join("node_modules", ".bin")))

buffer := bytes.NewBuffer(nil)
configArgs := []string{"config", "get", "yarn-offline-mirror"}
ip.logger.Subprocess("Running 'yarn %s'", strings.Join(configArgs, " "))

err := ip.executable.Execute(pexec.Execution{
Args: configArgs,
Stdout: io.MultiWriter(ip.logger.ActionWriter, buffer),
Stderr: io.MultiWriter(ip.logger.ActionWriter, buffer),
Args: []string{"config", "get", "yarn-offline-mirror"},
Stdout: buffer,
Stderr: buffer,
Env: environment,
Dir: workingDir,
})
if err != nil {
return fmt.Errorf("failed to execute yarn config output:\nerror: %s", err)
return fmt.Errorf("failed to execute yarn config output:\n%s\nerror: %s", buffer.String(), err)
}

installArgs := []string{"install", "--ignore-engines", "--frozen-lockfile"}
Expand Down
32 changes: 1 addition & 31 deletions install_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
Expect(run).To(BeTrue())
Expect(sha).To(Equal(""))
Expect(err).NotTo(HaveOccurred())
Expect(buffer.String()).ToNot(ContainLines(" Running 'yarn config list --silent'"))
})
})

Expand All @@ -90,23 +89,13 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
"--silent",
}))
Expect(execution.Dir).To(Equal(workingDir))
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config list --silent'",
" undefined",
" undefined",
))
})

it("succeeds when sha is missing", func() {
run, sha, err := installProcess.ShouldRun(workingDir, map[string]interface{}{})
Expect(run).To(BeTrue())
Expect(sha).To(Equal("some-other-sha"))
Expect(err).NotTo(HaveOccurred())
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config list --silent'",
" undefined",
" undefined",
))
})
})

Expand All @@ -125,11 +114,6 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
Expect(run).To(BeFalse())
Expect(sha).To(Equal(""))
Expect(err).NotTo(HaveOccurred())
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config list --silent'",
" undefined",
" undefined",
))
})
})

Expand Down Expand Up @@ -380,10 +364,6 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
Expect(executions[1].Env).To(ContainElement(MatchRegexp(`^PATH=.*:node_modules/.bin$`)))
Expect(executions[1].Dir).To(Equal(workingDir))
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config get yarn-offline-mirror'",
" stdout output",
" stderr output",
" undefined",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --production false --modules-folder %s'", filepath.Join(modulesLayerPath, "node_modules")),
" stdout output",
" stderr output",
Expand Down Expand Up @@ -415,10 +395,6 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
Expect(executions[1].Env).To(ContainElement(MatchRegexp(`^PATH=.*:node_modules/.bin$`)))
Expect(executions[1].Dir).To(Equal(workingDir))
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config get yarn-offline-mirror'",
" stdout output",
" stderr output",
" undefined",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --modules-folder %s'", filepath.Join(modulesLayerPath, "node_modules")),
" stdout output",
" stderr output",
Expand Down Expand Up @@ -466,13 +442,7 @@ func testInstallProcess(t *testing.T, context spec.G, it spec.S) {
}))
Expect(executions[1].Env).To(ContainElement(MatchRegexp(`^PATH=.*:node_modules/.bin$`)))
Expect(executions[1].Dir).To(Equal(workingDir))
Expect(buffer.String()).To(ContainLines(
" Running 'yarn config get yarn-offline-mirror'",
" warning some extraneous warning",
" warning some other warning",
fmt.Sprintf(" %s", filepath.Join(workingDir, "offline-mirror")),
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --offline --modules-folder %s'", filepath.Join(modulesLayerPath, "node_modules")),
))
Expect(buffer.String()).To(ContainSubstring(fmt.Sprintf("Running 'yarn install --ignore-engines --frozen-lockfile --offline --modules-folder %s'", filepath.Join(modulesLayerPath, "node_modules"))))
})
})

Expand Down
25 changes: 12 additions & 13 deletions integration/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func testLogging(t *testing.T, context spec.G, it spec.S) {
" Selected default build process: 'yarn install'",
"",
" Executing launch environment install process",
fmt.Sprintf(" Running yarn install --ignore-engines --frozen-lockfile --modules-folder /layers/%s/launch-modules/node_modules", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in (\d+)(\.\d+)?(ms|s)`),
"",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --modules-folder /layers/%s/launch-modules/node_modules'", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))
Expect(logs).To(ContainLines(
" Configuring launch environment",
" NODE_PROJECT_PATH -> \"/workspace\"",
fmt.Sprintf(" PATH -> \"$PATH:/layers/%s/launch-modules/node_modules/.bin\"", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
Expand All @@ -88,7 +88,6 @@ func testLogging(t *testing.T, context spec.G, it spec.S) {
" application/vnd.cyclonedx+json",
" application/spdx+json",
" application/vnd.syft+json",
"",
))
})
})
Expand Down Expand Up @@ -140,9 +139,9 @@ func testLogging(t *testing.T, context spec.G, it spec.S) {
" Selected default build process: 'yarn install'",
"",
" Executing launch environment install process",
fmt.Sprintf(" Running yarn install --ignore-engines --frozen-lockfile --offline --modules-folder /layers/%s/launch-modules/node_modules", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in (\d+)(\.\d+)?(ms|s)`),
"",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --offline --modules-folder /layers/%s/launch-modules/node_modules'", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))
Expect(logs).To(ContainLines(
" Configuring launch environment",
" NODE_PROJECT_PATH -> \"/workspace\"",
fmt.Sprintf(" PATH -> \"$PATH:/layers/%s/launch-modules/node_modules/.bin\"", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
Expand Down Expand Up @@ -201,9 +200,9 @@ func testLogging(t *testing.T, context spec.G, it spec.S) {
" Selected default build process: 'yarn install'",
"",
" Executing build environment install process",
fmt.Sprintf(" Running yarn install --ignore-engines --frozen-lockfile --production false --modules-folder /layers/%s/build-modules/node_modules", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in (\d+)(\.\d+)?(ms|s)`),
"",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --production false --modules-folder /layers/%s/build-modules/node_modules'", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))
Expect(logs).To(ContainLines(
" Configuring build environment",
` NODE_ENV -> "development"`,
fmt.Sprintf(" PATH -> \"$PATH:/layers/%s/build-modules/node_modules/.bin\"", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
Expand All @@ -223,9 +222,9 @@ func testLogging(t *testing.T, context spec.G, it spec.S) {
" Selected default build process: 'yarn install'",
"",
" Executing launch environment install process",
fmt.Sprintf(" Running yarn install --ignore-engines --frozen-lockfile --modules-folder /layers/%s/launch-modules/node_modules", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in (\d+)(\.\d+)?(ms|s)`),
"",
fmt.Sprintf(" Running 'yarn install --ignore-engines --frozen-lockfile --modules-folder /layers/%s/launch-modules/node_modules'", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
))
Expect(logs).To(ContainLines(
" Configuring launch environment",
" NODE_PROJECT_PATH -> \"/workspace\"",
fmt.Sprintf(" PATH -> \"$PATH:/layers/%s/launch-modules/node_modules/.bin\"", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
Expand Down

0 comments on commit defb665

Please sign in to comment.