Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Oct 19, 2023
1 parent 57b4655 commit 9712af4
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions build/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
testdatautils "github.com/jfrog/build-info-go/build/testdata"
"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/tests"
"github.com/jfrog/build-info-go/utils"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestGenerateBuildInfoForMavenProject(t *testing.T) {
assert.NoError(t, err)
// Create maven project
projectPath := filepath.Join(testdataDir, "maven", "project")
tmpProjectPath, cleanup := testdatautils.CreateTestProject(t, projectPath)
tmpProjectPath, cleanup := tests.CreateTestProject(t, projectPath)
defer cleanup()
// Add maven project as module in build-info.
mavenModule, err := mavenBuild.AddMavenModule(tmpProjectPath)
Expand All @@ -65,7 +65,7 @@ func TestGenerateBuildInfoForMavenProject(t *testing.T) {
match, err := entities.IsEqualModuleSlices(buildInfo.Modules, expectedModules)
assert.NoError(t, err)
if !match {
testdatautils.PrintBuildInfoMismatch(t, expectedModules, buildInfo.Modules)
tests.PrintBuildInfoMismatch(t, expectedModules, buildInfo.Modules)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newNpmModule(srcPath string, containingBuild *Build) (*NpmModule, error) {
}

// Read module name
packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExist(srcPath, npmVersion)
packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExists(srcPath, npmVersion)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions build/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

testdatautils "github.com/jfrog/build-info-go/build/testdata"
buildutils "github.com/jfrog/build-info-go/build/utils"
"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/tests"
"github.com/jfrog/build-info-go/utils"
"github.com/stretchr/testify/assert"
)
Expand All @@ -28,7 +28,7 @@ func TestGenerateBuildInfoForNpm(t *testing.T) {
// Create npm project.
path, err := filepath.Abs(filepath.Join(".", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project3", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project3", false, npmVersion)
defer cleanup()

// Install dependencies in the npm project.
Expand All @@ -45,11 +45,11 @@ func TestGenerateBuildInfoForNpm(t *testing.T) {

// Verify results.
expectedBuildInfoJson := filepath.Join(projectPath, "expected_npm_buildinfo.json")
expectedBuildInfo := testdatautils.GetBuildInfo(t, expectedBuildInfoJson)
expectedBuildInfo := tests.GetBuildInfo(t, expectedBuildInfoJson)
match, err := entities.IsEqualModuleSlices(buildInfo.Modules, expectedBuildInfo.Modules)
assert.NoError(t, err)
if !match {
testdatautils.PrintBuildInfoMismatch(t, expectedBuildInfo.Modules, buildInfo.Modules)
tests.PrintBuildInfoMismatch(t, expectedBuildInfo.Modules, buildInfo.Modules)
}
}

Expand All @@ -66,7 +66,7 @@ func TestFilterNpmArgsFlags(t *testing.T) {
// Create npm project.
path, err := filepath.Abs(filepath.Join(".", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project3", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project3", false, npmVersion)
defer cleanup()

// Set arguments in npmArgs.
Expand Down
8 changes: 4 additions & 4 deletions build/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/utils/pythonutils"

testdatautils "github.com/jfrog/build-info-go/build/testdata"
"github.com/jfrog/build-info-go/tests"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func testGenerateBuildInfoForPython(t *testing.T, pythonTool pythonutils.PythonT
assert.NoError(t, err)
// Create python project
projectPath := filepath.Join(testdataDir, "python", string(pythonTool))
tmpProjectPath, cleanup := testdatautils.CreateTestProject(t, projectPath)
tmpProjectPath, cleanup := tests.CreateTestProject(t, projectPath)
defer cleanup()

// Install dependencies in the pip project.
Expand All @@ -59,11 +59,11 @@ func testGenerateBuildInfoForPython(t *testing.T, pythonTool pythonutils.PythonT
if assert.NoError(t, err) {
// Verify results.
expectedBuildInfoJson := filepath.Join(projectPath, expectedResultsJson)
expectedBuildInfo := testdatautils.GetBuildInfo(t, expectedBuildInfoJson)
expectedBuildInfo := tests.GetBuildInfo(t, expectedBuildInfoJson)
match, err := entities.IsEqualModuleSlices(buildInfo.Modules, expectedBuildInfo.Modules)
assert.NoError(t, err)
if !match {
testdatautils.PrintBuildInfoMismatch(t, expectedBuildInfo.Modules, buildInfo.Modules)
tests.PrintBuildInfoMismatch(t, expectedBuildInfo.Modules, buildInfo.Modules)
}
}
}
4 changes: 2 additions & 2 deletions build/utils/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ type PackageInfo struct {
}

// Read and populate package name, version and scope from the package.json file in the provided directory.
// If package.json does not exist, return an empty PackageInfo object.
func ReadPackageInfoFromPackageJsonIfExist(packageJsonDirectory string, npmVersion *version.Version) (*PackageInfo, error) {
// If package.json does not exist, return an empty PackageInfo struct.
func ReadPackageInfoFromPackageJsonIfExists(packageJsonDirectory string, npmVersion *version.Version) (*PackageInfo, error) {
packageJson, err := os.ReadFile(filepath.Join(packageJsonDirectory, "package.json"))
if err != nil {
if os.IsNotExist(err) {
Expand Down
26 changes: 13 additions & 13 deletions build/utils/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/jfrog/build-info-go/entities"
"github.com/stretchr/testify/require"

testdatautils "github.com/jfrog/build-info-go/build/testdata"
"github.com/jfrog/build-info-go/tests"
"github.com/jfrog/build-info-go/utils"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -44,13 +44,13 @@ func TestReadPackageInfo(t *testing.T) {
}
}

func TestReadPackageInfoFromPackageJsonIfExist(t *testing.T) {
func TestReadPackageInfoFromPackageJsonIfExists(t *testing.T) {
// Prepare tests data
npmVersion, _, err := GetNpmVersionAndExecPath(logger)
assert.NoError(t, err)
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project1", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project1", false, npmVersion)
defer cleanup()

// Prepare test cases
Expand All @@ -66,7 +66,7 @@ func TestReadPackageInfoFromPackageJsonIfExist(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.testName, func(t *testing.T) {
// Read package info
packageInfo, err := ReadPackageInfoFromPackageJsonIfExist(testCase.packageJsonDirectory, npmVersion)
packageInfo, err := ReadPackageInfoFromPackageJsonIfExists(testCase.packageJsonDirectory, npmVersion)
assert.NoError(t, err)

// Remove "v" prefix, if exist
Expand All @@ -83,13 +83,13 @@ func TestReadPackageInfoFromPackageJsonIfExistErr(t *testing.T) {
// Prepare test data
npmVersion, _, err := GetNpmVersionAndExecPath(logger)
assert.NoError(t, err)
tempDir, createTempDirCallback := testdatautils.CreateTempDirWithCallbackAndAssert(t)
tempDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
assert.NoError(t, err)
defer createTempDirCallback()

// Create bad package.json file and expect error
assert.NoError(t, os.WriteFile(filepath.Join(tempDir, "package.json"), []byte("non json file"), 0600))
_, err = ReadPackageInfoFromPackageJsonIfExist(tempDir, npmVersion)
_, err = ReadPackageInfoFromPackageJsonIfExists(tempDir, npmVersion)
assert.IsType(t, &json.SyntaxError{}, err)
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func TestBundledDependenciesList(t *testing.T) {
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)

projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project1", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project1", false, npmVersion)
defer cleanup()
cacachePath := filepath.Join(projectPath, "tmpcache")
npmArgs := []string{"--cache=" + cacachePath}
Expand All @@ -200,7 +200,7 @@ func TestConflictsDependenciesList(t *testing.T) {
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)

projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project5", true, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project5", true, npmVersion)
defer cleanup()
cacachePath := filepath.Join(projectPath, "tmpcache")
npmArgs := []string{"--cache=" + cacachePath}
Expand All @@ -218,7 +218,7 @@ func TestDependencyWithNoIntegrity(t *testing.T) {
// Create the second npm project which has a transitive dependency without integrity (ansi-regex:5.0.0).
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project2", true, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project2", true, npmVersion)
defer cleanup()

// Run npm CI to create this special case where the 'ansi-regex:5.0.0' is missing the integrity.
Expand All @@ -241,7 +241,7 @@ func TestDependencyPackageLockOnly(t *testing.T) {
if !npmVersion.AtLeast("7.0.0") {
t.Skip("Running on npm v7 and above only, skipping...")
}
path, cleanup := testdatautils.CreateTestProject(t, filepath.Join("..", "testdata/npm/project6"))
path, cleanup := tests.CreateTestProject(t, filepath.Join("..", "testdata/npm/project6"))
defer cleanup()
assert.NoError(t, utils.MoveFile(filepath.Join(path, "package-lock_test.json"), filepath.Join(path, "package-lock.json")))
// sleep so the package.json modified time will be bigger than the package-lock.json, this make sure it will recalculate lock file.
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestDependenciesTreeDifferentBetweenOKs(t *testing.T) {
assert.NoError(t, err)
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project4", true, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project4", true, npmVersion)
defer cleanup()
cacachePath := filepath.Join(projectPath, "tmpcache")

Expand Down Expand Up @@ -357,7 +357,7 @@ func TestNpmProdFlag(t *testing.T) {
}
for _, entry := range testDependencyScopes {
func() {
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project3", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project3", false, npmVersion)
defer cleanup()
cacachePath := filepath.Join(projectPath, "tmpcache")
npmArgs := []string{"--cache=" + cacachePath, entry.scope}
Expand All @@ -382,7 +382,7 @@ func TestGetConfigCacheNpmIntegration(t *testing.T) {
// Create the first npm project which contains peerDependencies, devDependencies & bundledDependencies
path, err := filepath.Abs(filepath.Join("..", "testdata"))
assert.NoError(t, err)
projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project1", false, npmVersion)
projectPath, cleanup := tests.CreateNpmTest(t, path, "project1", false, npmVersion)
defer cleanup()
cachePath := filepath.Join(projectPath, "tmpcache")
npmArgs := []string{"--cache=" + cachePath}
Expand Down
2 changes: 1 addition & 1 deletion build/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newYarnModule(srcPath string, containingBuild *Build) (*YarnModule, error)
}

// Read module name
packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExist(srcPath, nil)
packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExists(srcPath, nil)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions build/yarn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"reflect"
"testing"

testdatautils "github.com/jfrog/build-info-go/build/testdata"
buildutils "github.com/jfrog/build-info-go/build/utils"
"github.com/jfrog/build-info-go/tests"

"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/utils"
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestAppendDependencyRecursively(t *testing.T) {

func TestGenerateBuildInfoForYarnProject(t *testing.T) {
// Copy the project directory to a temporary directory
tempDirPath, createTempDirCallback := testdatautils.CreateTempDirWithCallbackAndAssert(t)
tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testDataSource := filepath.Join("testdata", "yarn", "v2")
testDataTarget := filepath.Join(tempDirPath, "yarn")
Expand All @@ -107,7 +107,7 @@ func TestGenerateBuildInfoForYarnProject(t *testing.T) {

func TestCollectDepsForYarnProjectWithTraverse(t *testing.T) {
// Copy the project directory to a temporary directory
tempDirPath, createTempDirCallback := testdatautils.CreateTempDirWithCallbackAndAssert(t)
tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testDataSource := filepath.Join("testdata", "yarn", "v2")
testDataTarget := filepath.Join(tempDirPath, "yarn")
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestCollectDepsForYarnProjectWithTraverse(t *testing.T) {

func TestCollectDepsForYarnProjectWithErrorInTraverse(t *testing.T) {
// Copy the project directory to a temporary directory
tempDirPath, createTempDirCallback := testdatautils.CreateTempDirWithCallbackAndAssert(t)
tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testDataSource := filepath.Join("testdata", "yarn", "v2")
testDataTarget := filepath.Join(tempDirPath, "yarn")
Expand All @@ -171,7 +171,7 @@ func TestCollectDepsForYarnProjectWithErrorInTraverse(t *testing.T) {

func TestBuildYarnProjectWithArgs(t *testing.T) {
// Copy the project directory to a temporary directory
tempDirPath, createTempDirCallback := testdatautils.CreateTempDirWithCallbackAndAssert(t)
tempDirPath, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testDataSource := filepath.Join("testdata", "yarn", "v2")
testDataTarget := filepath.Join(tempDirPath, "yarn")
Expand Down
4 changes: 2 additions & 2 deletions buildinfoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/jfrog/build-info-go/build/testdata"
"github.com/jfrog/build-info-go/tests"
buildutils "github.com/jfrog/build-info-go/build/utils"
"github.com/jfrog/build-info-go/utils"

Expand Down Expand Up @@ -67,7 +67,7 @@ func validateBuildInfoSchema(t *testing.T, commandName, pathInTestData string, i
func prepareProject(t *testing.T, pathInTestdata string, install func()) func() {
wd, err := os.Getwd()
assert.NoError(t, err)
tempDir, cleanup := testdata.CreateTestProject(t, filepath.Join("build", "testdata", pathInTestdata))
tempDir, cleanup := tests.CreateTestProject(t, filepath.Join("build", "testdata", pathInTestdata))
assert.NoError(t, os.Chdir(tempDir))
install()

Expand Down
6 changes: 3 additions & 3 deletions build/testdata/test_helpers.go → tests/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testdata
package tests

import (
"encoding/json"
Expand Down Expand Up @@ -58,7 +58,7 @@ func CreateNpmTest(t *testing.T, testdataPath, projectDirName string, withOsInPa
npmVersionDir = filepath.Join(npmVersionDir, "linux")

default:
//MacOs
// MacOs
npmVersionDir = filepath.Join(npmVersionDir, "macos")
}
}
Expand All @@ -80,4 +80,4 @@ func CreateTempDirWithCallbackAndAssert(t *testing.T) (string, func()) {
return tempDirPath, func() {
assert.NoError(t, utils.RemoveTempDir(tempDirPath), "Couldn't remove temp dir")
}
}
}
4 changes: 2 additions & 2 deletions utils/pythonutils/piputils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

testdatautils "github.com/jfrog/build-info-go/build/testdata"
"github.com/jfrog/build-info-go/tests"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ var moduleNameTestProvider = []struct {
func TestDetermineModuleName(t *testing.T) {
for _, test := range moduleNameTestProvider {
t.Run(strings.Join([]string{test.projectName, test.moduleName}, "/"), func(t *testing.T) {
tmpProjectPath, cleanup := testdatautils.CreateTestProject(t, filepath.Join("..", "testdata", "pip", test.projectName))
tmpProjectPath, cleanup := tests.CreateTestProject(t, filepath.Join("..", "testdata", "pip", test.projectName))
defer cleanup()

// Determine module name
Expand Down
Loading

0 comments on commit 9712af4

Please sign in to comment.