Skip to content

Commit

Permalink
Added additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxBot committed Feb 18, 2025
1 parent d5f8ced commit 5cde89c
Show file tree
Hide file tree
Showing 7 changed files with 1,071 additions and 2 deletions.
121 changes: 119 additions & 2 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func TestYarn(t *testing.T) {
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnproject")
yarnProjectPath := filepath.Join(testDataTarget, "yarnprojectV2")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
Expand Down Expand Up @@ -714,6 +714,45 @@ func TestYarn(t *testing.T) {
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.YarnBuildName, artHttpDetails)
}

func TestYarnSetVersion(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)

// Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()

testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn")
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnprojectV2")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, yarnProjectPath)
defer chdirCallback()
cleanUpYarnGlobalFolder := clientTestUtils.SetEnvWithCallbackAndAssert(t, "YARN_GLOBAL_FOLDER", tempDirPath)
defer cleanUpYarnGlobalFolder()

// Add "localhost" to http whitelist
yarnExecPath, err := exec.LookPath("yarn")
assert.NoError(t, err)
// Get original http white list config
origWhitelist, err := yarn.ConfigGet("unsafeHttpWhitelist", yarnExecPath, true)
assert.NoError(t, err)
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", "[\"localhost\"]", yarnExecPath, true))
defer func() {
// Restore original whitelist config
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", origWhitelist, yarnExecPath, true))
}()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
err = jfrogCli.Exec("yarn", "set", "version", "3.2.1")
assert.NoError(t, err)
}

func TestYarnUpgradeToV4(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
Expand All @@ -726,7 +765,7 @@ func TestYarnUpgradeToV4(t *testing.T) {
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnproject")
yarnProjectPath := filepath.Join(testDataTarget, "yarnprojectV2")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
Expand All @@ -753,6 +792,84 @@ func TestYarnUpgradeToV4(t *testing.T) {
assert.Error(t, err)
}

func TestYarnInV4(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)

// Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()

testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn")
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnprojectV4")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, yarnProjectPath)
defer chdirCallback()
cleanUpYarnGlobalFolder := clientTestUtils.SetEnvWithCallbackAndAssert(t, "YARN_GLOBAL_FOLDER", tempDirPath)
defer cleanUpYarnGlobalFolder()

// Add "localhost" to http whitelist
yarnExecPath, err := exec.LookPath("yarn")
assert.NoError(t, err)
// Get original http white list config
origWhitelist, err := yarn.ConfigGet("unsafeHttpWhitelist", yarnExecPath, true)
assert.NoError(t, err)
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", "[\"localhost\"]", yarnExecPath, true))
defer func() {
// Restore original whitelist config
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", origWhitelist, yarnExecPath, true))
}()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
err = jfrogCli.Exec("yarn", "install")
assert.Error(t, err)
}

func TestYarnChangeVersionInV4(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)

// Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()

testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn")
testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn")
assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil))

yarnProjectPath := filepath.Join(testDataTarget, "yarnprojectV4")
assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false))

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, yarnProjectPath)
defer chdirCallback()
cleanUpYarnGlobalFolder := clientTestUtils.SetEnvWithCallbackAndAssert(t, "YARN_GLOBAL_FOLDER", tempDirPath)
defer cleanUpYarnGlobalFolder()

// Add "localhost" to http whitelist
yarnExecPath, err := exec.LookPath("yarn")
assert.NoError(t, err)
// Get original http white list config
origWhitelist, err := yarn.ConfigGet("unsafeHttpWhitelist", yarnExecPath, true)
assert.NoError(t, err)
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", "[\"localhost\"]", yarnExecPath, true))
defer func() {
// Restore original whitelist config
assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", origWhitelist, yarnExecPath, true))
}()

jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
err = jfrogCli.Exec("yarn", "set", "version", "3.2.1")
assert.NoError(t, err)
}

// Checks if the expected dependencies match the actual dependencies. Only the dependencies' IDs and scopes (not more than one scope) are compared.
func equalDependenciesSlices(t *testing.T, expectedDependencies []expectedDependency, actualDependencies []buildinfo.Dependency) {
assert.Equal(t, len(expectedDependencies), len(actualDependencies))
Expand Down
File renamed without changes.
File renamed without changes.
934 changes: 934 additions & 0 deletions testdata/yarn/yarnprojectV4/.yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions testdata/yarn/yarnprojectV4/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-4.6.0.cjs
17 changes: 17 additions & 0 deletions testdata/yarn/yarnprojectV4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "jfrog-cli-tests",
"version": "v1.0.0",
"description": "test package",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xml": "1.0.1"
},
"devDependencies": {
"json": "9.0.6"
}
}

0 comments on commit 5cde89c

Please sign in to comment.