-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
323 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,24 +9,22 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetProjectNameFromFileContent(t *testing.T) { | ||
tests := []struct { | ||
fileContent string | ||
expectedProjectName string | ||
func TestGetProjectNameAndVersionFromFileContent(t *testing.T) { | ||
testCases := []struct { | ||
fileContent string | ||
expectedProjectName string | ||
expectedProjectVersion string | ||
}{ | ||
{"Metadata-Version: 1.0\nName: jfrog-python-example-1\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN", "jfrog-python-example-1:1.0"}, | ||
{"Metadata-Version: Name: jfrog-python-example-2\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN\nName: jfrog-python-example-2\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]", "jfrog-python-example-2:1.0"}, | ||
{"Name:Metadata-Version: 3.0\nName: jfrog-python-example-3\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]\nName: jfrog-python-example-4", "jfrog-python-example-3:1.0"}, | ||
{"Metadata-Version: 1.0\nName: jfrog-python-example-1\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN", "jfrog-python-example-1", "1.0"}, | ||
{"Metadata-Version: Name: jfrog-python-example-2\nLicense: UNKNOWN\nDescription: UNKNOWN\nPlatform: UNKNOWN\nName: jfrog-python-example-2\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]", "jfrog-python-example-2", "1.0"}, | ||
{"Name:Metadata-Version: 3.0\nName: jfrog-python-example-3\nVersion: 1.0\nSummary: Project example for building Python project with JFrog products\nHome-page: https://github.com/jfrog/project-examples\nAuthor: JFrog\nAuthor-email: [email protected]\nName: jfrog-python-example-4", "jfrog-python-example-3", "1.0"}, | ||
} | ||
|
||
for _, test := range tests { | ||
actualValue, err := getProjectIdFromFileContent([]byte(test.fileContent)) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if actualValue != test.expectedProjectName { | ||
t.Errorf("Expected value: %s, got: %s.", test.expectedProjectName, actualValue) | ||
} | ||
for _, test := range testCases { | ||
projectName, projectVersion, err := getProjectNameAndVersionFromFileContent([]byte(test.fileContent)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, test.expectedProjectName, projectName) | ||
assert.Equal(t, test.expectedProjectVersion, projectVersion) | ||
} | ||
} | ||
|
||
|
@@ -40,16 +38,18 @@ var moduleNameTestProvider = []struct { | |
{"setuppyproject", "overidden-module", "overidden-module", "jfrog-python-example:1.0"}, | ||
{"requirementsproject", "", "", ""}, | ||
{"requirementsproject", "overidden-module", "overidden-module", ""}, | ||
{"pyproject", "", "jfrog-python-example:1.0", "pip-project-with-pyproject:1.2.3"}, | ||
{"pyproject", "overidden-module", "overidden-module", "pip-project-with-pyproject:1.2.3"}, | ||
} | ||
|
||
func TestDetermineModuleName(t *testing.T) { | ||
func TestGetPipProjectId(t *testing.T) { | ||
for _, test := range moduleNameTestProvider { | ||
t.Run(strings.Join([]string{test.projectName, test.moduleName}, "/"), func(t *testing.T) { | ||
tmpProjectPath, cleanup := tests.CreateTestProject(t, filepath.Join("..", "testdata", "pip", test.projectName)) | ||
defer cleanup() | ||
|
||
// Determine module name | ||
packageName, err := getPackageNameFromSetuppy(tmpProjectPath) | ||
packageName, err := getPipProjectId(tmpProjectPath) | ||
if assert.NoError(t, err) { | ||
assert.Equal(t, test.expectedPackageName, packageName) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.