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 non-interactive config without providing server ID #915

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion common/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (cc *ConfigCommand) resolveServerId() string {
if cc.details.ServerId != "" {
return cc.details.ServerId
}
if cc.defaultDetails.ServerId != "" {
if cc.defaultDetails != nil && cc.defaultDetails.ServerId != "" {
return cc.defaultDetails.ServerId
}
return config.DefaultServerId
Expand Down
25 changes: 23 additions & 2 deletions common/commands/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ func TestUsernameSavedLowercase(t *testing.T) {
assert.Equal(t, outputConfig.User, "admin", "The config command is supposed to save username as lowercase")
}

func TestDefaultServerId(t *testing.T) {
inputDetails := tests.CreateTestServerDetails()
inputDetails.User = "admin"
inputDetails.Password = "password"
// Remove server ID to verify the default one will be applied in non-interactive execution.
inputDetails.ServerId = ""

doConfig(t, "", inputDetails, false, true, false)
outputConfig, err := GetConfig(config.DefaultServerId, false)
assert.NoError(t, err)
assert.Equal(t, config.DefaultServerId, outputConfig.ServerId)
assert.NoError(t, NewConfigCommand(Delete, config.DefaultServerId).Run())
}

func TestArtifactorySshKey(t *testing.T) {
inputDetails := tests.CreateTestServerDetails()
inputDetails.SshKeyPath = "/tmp/sshKey"
Expand Down Expand Up @@ -172,6 +186,10 @@ func TestBasicAuthOnlyOption(t *testing.T) {
}

func TestMakeDefaultOption(t *testing.T) {
cleanUpJfrogHome, err := utilsTests.SetJfrogHome()
assert.NoError(t, err)
defer cleanUpJfrogHome()

originalDefault := tests.CreateTestServerDetails()
originalDefault.ServerId = "originalDefault"
originalDefault.IsDefault = false
Expand All @@ -186,7 +204,6 @@ func TestMakeDefaultOption(t *testing.T) {
// Config a second server and pass the makeDefault option.
configAndAssertDefault(t, newDefault, true)
defer deleteServer(t, newDefault.ServerId)

}

func configAndAssertDefault(t *testing.T, inputDetails *config.ServerDetails, makeDefault bool) {
Expand Down Expand Up @@ -321,11 +338,15 @@ func configAndGetTestServer(t *testing.T, inputDetails *config.ServerDetails, ba
}

func configAndGetServer(t *testing.T, serverId string, inputDetails *config.ServerDetails, basicAuthOnly, interactive, makeDefault bool) (*config.ServerDetails, error) {
doConfig(t, serverId, inputDetails, basicAuthOnly, interactive, makeDefault)
return GetConfig(serverId, false)
}

func doConfig(t *testing.T, serverId string, inputDetails *config.ServerDetails, basicAuthOnly, interactive, makeDefault bool) {
configCmd := NewConfigCommand(AddOrEdit, serverId).SetDetails(inputDetails).SetUseBasicAuthOnly(basicAuthOnly).
SetInteractive(interactive).SetMakeDefault(makeDefault)
configCmd.disablePrompts = true
assert.NoError(t, configCmd.Run())
return GetConfig(serverId, false)
}

func configStructToString(t *testing.T, artConfig *config.ServerDetails) string {
Expand Down
Loading