From c4908eef6019ae7c597c3142cf15d50248aeb4a5 Mon Sep 17 00:00:00 2001 From: Eran Turgeman Date: Thu, 14 Mar 2024 15:06:27 +0200 Subject: [PATCH 1/3] fix testdata project path in yarn tests --- commands/audit/sca/yarn/yarn_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/commands/audit/sca/yarn/yarn_test.go b/commands/audit/sca/yarn/yarn_test.go index 38bd3216..8fe382c4 100644 --- a/commands/audit/sca/yarn/yarn_test.go +++ b/commands/audit/sca/yarn/yarn_test.go @@ -55,7 +55,7 @@ func TestParseYarnDependenciesList(t *testing.T) { func TestIsInstallRequired(t *testing.T) { tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() - yarnProjectPath := filepath.Join("..", "..", "..", "testdata", "yarn-project") + yarnProjectPath := filepath.Join("..", "..", "..", "..", "tests", "testdata", "projects", "package-managers", "yarn", "yarn-project") assert.NoError(t, utils2.CopyDir(yarnProjectPath, tempDirPath, true, nil)) installRequired, err := isInstallRequired(tempDirPath, []string{}) assert.NoError(t, err) @@ -85,8 +85,10 @@ func TestRunYarnInstallAccordingToVersion(t *testing.T) { func executeRunYarnInstallAccordingToVersionAndVerifyInstallation(t *testing.T, params []string) { tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() - yarnProjectPath := filepath.Join("..", "..", "..", "testdata", "yarn-project") - assert.NoError(t, utils2.CopyDir(yarnProjectPath, tempDirPath, true, nil)) + yarnProjectPath := filepath.Join("..", "..", "..", "..", "tests", "testdata", "projects", "package-managers", "yarn", "yarn-project") + fullPath, err := filepath.Abs(yarnProjectPath) + assert.NoError(t, err) + assert.NoError(t, utils2.CopyDir(fullPath, tempDirPath, true, nil)) executablePath, err := biutils.GetYarnExecutable() assert.NoError(t, err) From 0eac486b53a542af30466b2c84b3f48b69345244 Mon Sep 17 00:00:00 2001 From: Eran Turgeman Date: Thu, 14 Mar 2024 15:24:04 +0200 Subject: [PATCH 2/3] safety check added --- commands/audit/sca/yarn/yarn_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/commands/audit/sca/yarn/yarn_test.go b/commands/audit/sca/yarn/yarn_test.go index 8fe382c4..7c96bc86 100644 --- a/commands/audit/sca/yarn/yarn_test.go +++ b/commands/audit/sca/yarn/yarn_test.go @@ -6,6 +6,7 @@ import ( utils2 "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/tests" "github.com/jfrog/jfrog-cli-security/utils" + "github.com/jfrog/jfrog-client-go/utils/io/fileutils" xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils" "github.com/stretchr/testify/assert" "path/filepath" @@ -60,6 +61,14 @@ func TestIsInstallRequired(t *testing.T) { installRequired, err := isInstallRequired(tempDirPath, []string{}) assert.NoError(t, err) assert.True(t, installRequired) + + // Validates we are not operating on an empty test dir. + // Yarn 1, That is currently installed on the machines that are running the tests, allows running 'install' on an empty project. This makes the test pass without actually checking what needs to be checked. + // This check can be deleted after the Yarn version on the runner machine will be upgraded to Yarn berry. + isTempDirEmpty, err := fileutils.IsDirEmpty(tempDirPath) + assert.NoError(t, err) + assert.False(t, isTempDirEmpty) + executablePath, err := biutils.GetYarnExecutable() assert.NoError(t, err) @@ -86,9 +95,14 @@ func executeRunYarnInstallAccordingToVersionAndVerifyInstallation(t *testing.T, tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() yarnProjectPath := filepath.Join("..", "..", "..", "..", "tests", "testdata", "projects", "package-managers", "yarn", "yarn-project") - fullPath, err := filepath.Abs(yarnProjectPath) + assert.NoError(t, utils2.CopyDir(yarnProjectPath, tempDirPath, true, nil)) + + // Validates we are not operating on an empty test dir. + // Yarn 1, That is currently installed on the machines that are running the tests, allows running 'install' on an empty project. This makes the test pass without actually checking what needs to be checked. + // This check can be deleted after the Yarn version on the runner machine will be upgraded to Yarn berry. + isTempDirEmpty, err := fileutils.IsDirEmpty(tempDirPath) assert.NoError(t, err) - assert.NoError(t, utils2.CopyDir(fullPath, tempDirPath, true, nil)) + assert.False(t, isTempDirEmpty) executablePath, err := biutils.GetYarnExecutable() assert.NoError(t, err) From 2aaeef3e7c012c786cb93a0d156ff5ddff0db0b5 Mon Sep 17 00:00:00 2001 From: Eran Turgeman Date: Thu, 14 Mar 2024 15:33:26 +0200 Subject: [PATCH 3/3] . --- commands/audit/sca/yarn/yarn_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/commands/audit/sca/yarn/yarn_test.go b/commands/audit/sca/yarn/yarn_test.go index 7c96bc86..faad4d64 100644 --- a/commands/audit/sca/yarn/yarn_test.go +++ b/commands/audit/sca/yarn/yarn_test.go @@ -62,9 +62,6 @@ func TestIsInstallRequired(t *testing.T) { assert.NoError(t, err) assert.True(t, installRequired) - // Validates we are not operating on an empty test dir. - // Yarn 1, That is currently installed on the machines that are running the tests, allows running 'install' on an empty project. This makes the test pass without actually checking what needs to be checked. - // This check can be deleted after the Yarn version on the runner machine will be upgraded to Yarn berry. isTempDirEmpty, err := fileutils.IsDirEmpty(tempDirPath) assert.NoError(t, err) assert.False(t, isTempDirEmpty) @@ -97,9 +94,6 @@ func executeRunYarnInstallAccordingToVersionAndVerifyInstallation(t *testing.T, yarnProjectPath := filepath.Join("..", "..", "..", "..", "tests", "testdata", "projects", "package-managers", "yarn", "yarn-project") assert.NoError(t, utils2.CopyDir(yarnProjectPath, tempDirPath, true, nil)) - // Validates we are not operating on an empty test dir. - // Yarn 1, That is currently installed on the machines that are running the tests, allows running 'install' on an empty project. This makes the test pass without actually checking what needs to be checked. - // This check can be deleted after the Yarn version on the runner machine will be upgraded to Yarn berry. isTempDirEmpty, err := fileutils.IsDirEmpty(tempDirPath) assert.NoError(t, err) assert.False(t, isTempDirEmpty)