File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,22 @@ const (
1515)
1616
1717type LoginCommand struct {
18+ serverId string
1819}
1920
2021func NewLoginCommand () * LoginCommand {
2122 return & LoginCommand {}
2223}
2324
25+ func (lc * LoginCommand ) SetServerId (serverId string ) * LoginCommand {
26+ lc .serverId = serverId
27+ return lc
28+ }
29+
2430func (lc * LoginCommand ) Run () error {
31+ if lc .serverId != "" {
32+ return existingServerLogin (lc .serverId )
33+ }
2534 configurations , err := config .GetAllServersConfigs ()
2635 if err != nil {
2736 return err
Original file line number Diff line number Diff line change 1+ package login
2+
3+ import (
4+ "testing"
5+
6+ "github.com/jfrog/jfrog-cli-core/v2/utils/config"
7+ utilsTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
8+ "github.com/stretchr/testify/assert"
9+ "github.com/stretchr/testify/require"
10+ )
11+
12+ func TestSetServerId (t * testing.T ) {
13+ lc := NewLoginCommand ()
14+ result := lc .SetServerId ("my-server" )
15+ assert .Equal (t , "my-server" , lc .serverId )
16+ // Verify fluent API returns the same instance
17+ assert .Same (t , lc , result )
18+ }
19+
20+ func TestRunWithNonExistentServerId (t * testing.T ) {
21+ cleanUp , err := utilsTests .SetJfrogHome ()
22+ require .NoError (t , err )
23+ defer cleanUp ()
24+
25+ // At least one server must exist so GetConfig actually looks up by ID
26+ err = config .SaveServersConf ([]* config.ServerDetails {
27+ {ServerId : "other-server" , Url : "https://example.jfrog.io/" },
28+ })
29+ require .NoError (t , err )
30+
31+ lc := NewLoginCommand ().SetServerId ("non-existent-server" )
32+ err = lc .Run ()
33+ assert .ErrorContains (t , err , "non-existent-server" )
34+ }
35+
You can’t perform that action at this time.
0 commit comments