Skip to content

Commit

Permalink
introduce back --no-save,change directory name, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashlymat committed Jul 3, 2023
1 parent 5d599d4 commit de79343
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
npmBomFilename = "bom-npm.xml"
cycloneDxNpmPackageVersion = "@cyclonedx/[email protected]"
cycloneDxNpmInstallationFolder = "./bomFolder"
cycloneDxNpmInstallationFolder = "./tmp"
cycloneDxBomPackageVersion = "@cyclonedx/bom@^3.10.6"
cycloneDxSchemaVersion = "1.4"
)
Expand Down Expand Up @@ -358,7 +358,7 @@ func (exec *Execute) checkIfLockFilesExist() (bool, bool, error) {
// CreateBOM generates BOM file using CycloneDX from all package.json files
func (exec *Execute) CreateBOM(packageJSONFiles []string) error {
// Install cyclonedx-npm in a new folder (to avoid extraneous errors) and generate BOM
cycloneDxNpmInstallParams := []string{"install", cycloneDxNpmPackageVersion, "--prefix", cycloneDxNpmInstallationFolder}
cycloneDxNpmInstallParams := []string{"install", "--no-save", cycloneDxNpmPackageVersion, "--prefix", cycloneDxNpmInstallationFolder}
cycloneDxNpmRunParams := []string{"--output-format", "XML", "--spec-version", cycloneDxSchemaVersion, "--output-file"}

// Install cyclonedx/bom with --nosave and generate BOM.
Expand Down
10 changes: 5 additions & 5 deletions pkg/npm/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func TestNpm(t *testing.T) {
Options: options,
}
err := exec.CreateBOM([]string{"package.json", filepath.Join("src", "package.json")})
cycloneDxNpmInstallParams := []string{"install", "@cyclonedx/[email protected]", "--prefix", "./bomFolder"}
cycloneDxNpmInstallParams := []string{"install", "--no-save", "@cyclonedx/[email protected]", "--prefix", "./tmp"}
cycloneDxNpmRunParams := []string{
"--output-format",
"XML",
Expand All @@ -370,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: "./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])
assert.Equal(t, mock.ExecCall{Exec: "./tmp/node_modules/.bin/cyclonedx-npm", Params: append(cycloneDxNpmRunParams, "bom-npm.xml", "package.json")}, utils.execRunner.Calls[1])
assert.Equal(t, mock.ExecCall{Exec: "./tmp/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 @@ -383,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 @cyclonedx/[email protected] --prefix ./bomFolder": fmt.Errorf("failed to install CycloneDX BOM")}
utils.execRunner.ShouldFailOnCommand = map[string]error{"npm install --no-save @cyclonedx/[email protected] --prefix ./tmp": fmt.Errorf("failed to install CycloneDX BOM")}

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

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

0 comments on commit de79343

Please sign in to comment.