1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

fix tests

This commit is contained in:
Ashly Mathew
2025-06-20 12:31:33 +02:00
parent 0ada6189ff
commit dc97a14623
10 changed files with 12147 additions and 16 deletions

12131
cmd/cover.out Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -235,7 +235,7 @@ func runDetect(ctx context.Context, config detectExecuteScanOptions, utils detec
buildDescriptorList = []string{"package.json"}
}
err := npmExecutor.InstallAllDependencies(buildDescriptorList)
err := npmExecutor.InstallAllDependencies(buildDescriptorList, "")
if err != nil {
return err
}

View File

@@ -117,7 +117,7 @@ func (bundle *mtaBuildUtilsBundle) SetNpmRegistries(defaultNpmRegistry string) e
func (bundle *mtaBuildUtilsBundle) InstallAllDependencies(defaultNpmRegistry string) error {
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: defaultNpmRegistry, ExecRunner: bundle}
npmExecutor := npm.NewExecutor(npmExecutorOptions)
return npmExecutor.InstallAllDependencies(npmExecutor.FindPackageJSONFiles())
return npmExecutor.InstallAllDependencies(npmExecutor.FindPackageJSONFiles(), "")
}
func (bundle *mtaBuildUtilsBundle) DownloadAndCopySettingsFiles(globalSettingsFile string, projectSettingsFile string) error {

View File

@@ -88,7 +88,7 @@ func runNpmExecuteLint(npmExecutor npm.Executor, utils lintUtils, config *npmExe
if len(packagesWithLintScript) > 0 {
if config.Install {
err := npmExecutor.InstallAllDependencies(packagesWithLintScript)
err := npmExecutor.InstallAllDependencies(packagesWithLintScript, "")
if err != nil {
return err
}
@@ -100,7 +100,7 @@ func runNpmExecuteLint(npmExecutor npm.Executor, utils lintUtils, config *npmExe
}
} else {
if config.Install {
err := npmExecutor.InstallAllDependencies(packageJSONFiles)
err := npmExecutor.InstallAllDependencies(packageJSONFiles, "")
if err != nil {
return err
}

View File

@@ -144,7 +144,7 @@ func (w *whitesourceUtilsBundle) FindPackageJSONFiles(config *ws.ScanOptions) ([
}
func (w *whitesourceUtilsBundle) InstallAllNPMDependencies(config *ws.ScanOptions, packageJSONFiles []string) error {
return w.getNpmExecutor(config).InstallAllDependencies(packageJSONFiles)
return w.getNpmExecutor(config).InstallAllDependencies(packageJSONFiles, "")
}
func (w *whitesourceUtilsBundle) SetOptions(o piperhttp.ClientOptions) {

View File

@@ -38,7 +38,7 @@ var cycloneDxCliUrl = map[struct{ os, arch string }]string{
// It supports both pnpm and other package managers (npm/yarn) with different BOM generation strategies.
func (exec *Execute) CreateBOM(packageJSONFiles []string) error {
log.Entry().Debug("Detecting package manager...")
pm, err := exec.detectPackageManager()
pm, err := exec.detectPackageManager("")
if err != nil {
return fmt.Errorf("failed to detect package manager (looking for package.json, package-lock.json, pnpm-lock.yaml): %w", err)
}

View File

@@ -96,7 +96,7 @@ func (n *NpmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOption
}
// InstallAllDependencies mock implementation
func (n *NpmExecutorMock) InstallAllDependencies(packageJSONFiles []string) error {
func (n *NpmExecutorMock) InstallAllDependencies(packageJSONFiles []string, pnpmVersion string) error {
allPackages := n.FindPackageJSONFiles()
if len(packageJSONFiles) != len(allPackages) {
return fmt.Errorf("packageJSONFiles != n.FindPackageJSONFiles()")

View File

@@ -29,7 +29,7 @@ type Executor interface {
FindPackageJSONFilesWithExcludes(excludeList []string) ([]string, error)
FindPackageJSONFilesWithScript(packageJSONFiles []string, script string) ([]string, error)
RunScriptsInAllPackages(runScripts []string, runOptions []string, scriptOptions []string, virtualFrameBuffer bool, excludeList []string, packagesList []string) error
InstallAllDependencies(packageJSONFiles []string, string) error
InstallAllDependencies(packageJSONFiles []string, pnpmVersion string) error
PublishAllPackages(packageJSONFiles []string, registry, username, password string, packBeforePublish bool, buildCoordinates *[]versioning.Coordinates) error
SetNpmRegistries() error
CreateBOM(packageJSONFiles []string) error

View File

@@ -139,7 +139,7 @@ func TestNpm(t *testing.T) {
Utils: &utils,
Options: options,
}
err := exec.install("package.json")
err := exec.install("package.json", "")
if assert.NoError(t, err) {
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
@@ -159,7 +159,7 @@ func TestNpm(t *testing.T) {
Utils: &utils,
Options: options,
}
err := exec.install("package.json")
err := exec.install("package.json", "")
if assert.NoError(t, err) {
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
@@ -180,7 +180,7 @@ func TestNpm(t *testing.T) {
Utils: &utils,
Options: options,
}
err := exec.install("package.json")
err := exec.install("package.json", "")
if assert.NoError(t, err) {
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
@@ -205,7 +205,7 @@ func TestNpm(t *testing.T) {
Utils: &utils,
Options: options,
}
err := exec.install("package.json")
err := exec.install("package.json", "")
if assert.NoError(t, err) {
fmt.Println(utils.execRunner.Calls)
@@ -236,7 +236,7 @@ func TestNpm(t *testing.T) {
Utils: &utils,
Options: options,
}
err := exec.InstallAllDependencies([]string{"package.json", filepath.Join("src", "package.json")})
err := exec.InstallAllDependencies([]string{"package.json", filepath.Join("src", "package.json")}, "")
if assert.NoError(t, err) {
if assert.Equal(t, 4, len(utils.execRunner.Calls)) {

View File

@@ -70,7 +70,7 @@ func TestPackageManager(t *testing.T) {
Options: ExecutorOptions{},
}
pm, err := exec.detectPackageManager()
pm, err := exec.detectPackageManager("")
assert.NoError(t, err)
assert.Equal(t, tt.expectedPM, pm.Name)
@@ -105,7 +105,7 @@ func TestPackageManager(t *testing.T) {
Options: ExecutorOptions{},
}
_, err := exec.detectPackageManager()
_, err := exec.detectPackageManager("")
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
})
@@ -158,7 +158,7 @@ func TestPackageManager(t *testing.T) {
Options: ExecutorOptions{},
}
err := exec.install("package.json")
err := exec.install("package.json", "")
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)