Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testdata project path in Yarn tests #40

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions commands/audit/sca/yarn/yarn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,11 +56,19 @@ 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)
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)

Expand All @@ -85,9 +94,16 @@ 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")
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.
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved
isTempDirEmpty, err := fileutils.IsDirEmpty(tempDirPath)
assert.NoError(t, err)
assert.False(t, isTempDirEmpty)

executablePath, err := biutils.GetYarnExecutable()
assert.NoError(t, err)

Expand Down
Loading