Skip to content

Commit 2f110c4

Browse files
authored
Add GetRepositoryPackageType to project setup (#126)
1 parent 79161b2 commit 2f110c4

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

artifactory/commands/setup/setup.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ func IsSupportedPackageManager(packageManager project.ProjectType) bool {
104104
return exists
105105
}
106106

107+
// GetRepositoryPackageType gets the package type and returns the corresponding repository package type.
108+
// For example, for pip or poetry the repository package type is "pypi".
109+
func GetRepositoryPackageType(packageManager project.ProjectType) (string, error) {
110+
packageType, exists := packageManagerToRepositoryPackageType[packageManager]
111+
if !exists {
112+
return "", errorutils.CheckErrorf("unsupported package manager: %s", packageManager)
113+
}
114+
return packageType, nil
115+
}
116+
107117
// CommandName returns the name of the login command.
108118
func (sc *SetupCommand) CommandName() string {
109119
return sc.commandName

artifactory/commands/setup/setup_test.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,16 @@ func TestConfigureGo_UnsetEnv(t *testing.T) {
342342

343343
// Test that configureGo unsets any existing multi-entry GOPROXY env var before configuring.
344344
func TestConfigureGo_UnsetEnv_MultiEntry(t *testing.T) {
345-
testCmd := createTestSetupCommand(project.Go)
346-
// Simulate existing multi-entry GOPROXY in environment
347-
t.Setenv("GOPROXY", "user:pass@dummy,goproxy2")
348-
// Ensure server details have credentials so configureGo proceeds
349-
testCmd.serverDetails.SetAccessToken(dummyToken)
350-
351-
// Invoke configureGo directly
352-
require.NoError(t, testCmd.configureGo())
353-
// After calling, the GOPROXY env var should be cleared
354-
assert.Empty(t, os.Getenv("GOPROXY"), "GOPROXY should be unset by configureGo to avoid env override for multi-entry lists")
345+
testCmd := createTestSetupCommand(project.Go)
346+
// Simulate existing multi-entry GOPROXY in environment
347+
t.Setenv("GOPROXY", "user:pass@dummy,goproxy2")
348+
// Ensure server details have credentials so configureGo proceeds
349+
testCmd.serverDetails.SetAccessToken(dummyToken)
350+
351+
// Invoke configureGo directly
352+
require.NoError(t, testCmd.configureGo())
353+
// After calling, the GOPROXY env var should be cleared
354+
assert.Empty(t, os.Getenv("GOPROXY"), "GOPROXY should be unset by configureGo to avoid env override for multi-entry lists")
355355
}
356356

357357
func TestSetupCommand_Gradle(t *testing.T) {
@@ -468,6 +468,24 @@ func TestIsSupportedPackageManager(t *testing.T) {
468468
assert.False(t, IsSupportedPackageManager(project.Cocoapods), "Package manager Cocoapods should not be supported")
469469
}
470470

471+
func TestGetRepositoryPackageType(t *testing.T) {
472+
// Test supported package managers
473+
for projectType, packageType := range packageManagerToRepositoryPackageType {
474+
t.Run("Supported - "+projectType.String(), func(t *testing.T) {
475+
actualType, err := GetRepositoryPackageType(projectType)
476+
require.NoError(t, err)
477+
assert.Equal(t, packageType, actualType)
478+
})
479+
}
480+
481+
// Test unsupported package manager
482+
t.Run("Unsupported", func(t *testing.T) {
483+
_, err := GetRepositoryPackageType(project.Cocoapods)
484+
require.Error(t, err)
485+
assert.Contains(t, err.Error(), "unsupported package manager")
486+
})
487+
}
488+
471489
func TestSetupCommand_Maven(t *testing.T) {
472490
// Retrieve the home directory and construct the settings.xml file path.
473491
homeDir, err := os.UserHomeDir()

0 commit comments

Comments
 (0)