Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashlymat committed Jul 3, 2023
1 parent 3ee7541 commit bb1b742
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/npm/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,8 @@ func TestNpm(t *testing.T) {
Options: options,
}
err := exec.CreateBOM([]string{"package.json", filepath.Join("src", "package.json")})
cycloneDxNpmInstallParams := []string{"install", "--global", "@cyclonedx/[email protected]"}
cycloneDxNpmInstallParams := []string{"install", "@cyclonedx/[email protected]", "--prefix", "./bomFolder"}
cycloneDxNpmRunParams := []string{
cycloneDxNpmPackageVersion,
"--output-format",
"XML",
"--spec-version",
Expand All @@ -371,8 +370,8 @@ func TestNpm(t *testing.T) {
if assert.NoError(t, err) {
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: cycloneDxNpmInstallParams}, utils.execRunner.Calls[0])
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: append(cycloneDxNpmRunParams, "bom-npm.xml", "package.json")}, utils.execRunner.Calls[1])
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: append(cycloneDxNpmRunParams, filepath.Join("src", "bom-npm.xml"), filepath.Join("src", "package.json"))}, utils.execRunner.Calls[2])
assert.Equal(t, mock.ExecCall{Exec: "./bomFolder/node_modules/.bin/cyclonedx-npm", Params: append(cycloneDxNpmRunParams, "bom-npm.xml", "package.json")}, utils.execRunner.Calls[1])
assert.Equal(t, mock.ExecCall{Exec: "./bomFolder/node_modules/.bin/cyclonedx-npm", Params: append(cycloneDxNpmRunParams, filepath.Join("src", "bom-npm.xml"), filepath.Join("src", "package.json"))}, utils.execRunner.Calls[2])
}

}
Expand All @@ -384,7 +383,7 @@ func TestNpm(t *testing.T) {
utils.AddFile("package-lock.json", []byte("{}"))
utils.AddFile(filepath.Join("src", "package.json"), []byte("{\"scripts\": { \"ci-lint\": \"exit 0\" } }"))
utils.AddFile(filepath.Join("src", "package-lock.json"), []byte("{}"))
utils.execRunner.ShouldFailOnCommand = map[string]error{"npm install --global @cyclonedx/[email protected]": fmt.Errorf("failed to install CycloneDX BOM")}
utils.execRunner.ShouldFailOnCommand = map[string]error{"npm install @cyclonedx/[email protected] --prefix ./bomFolder": fmt.Errorf("failed to install CycloneDX BOM")}

options := ExecutorOptions{}
options.DefaultNpmRegistry = "foo.bar"
Expand All @@ -394,7 +393,7 @@ func TestNpm(t *testing.T) {
Options: options,
}
err := exec.CreateBOM([]string{"package.json", filepath.Join("src", "package.json")})
cycloneDxNpmInstallParams := []string{"install", "--global", "@cyclonedx/[email protected]"}
cycloneDxNpmInstallParams := []string{"install", "@cyclonedx/[email protected]", "--prefix", "./bomFolder"}

cycloneDxBomInstallParams := []string{"install", cycloneDxBomPackageVersion, "--no-save"}
cycloneDxBomRunParams := []string{
Expand Down

0 comments on commit bb1b742

Please sign in to comment.