Skip to content

Commit 83dd2cb

Browse files
committed
Removed cyclic dependency on cli-artifactory
1 parent d005557 commit 83dd2cb

File tree

7 files changed

+97
-17
lines changed

7 files changed

+97
-17
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package generic
2+
3+
import (
4+
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
5+
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
6+
)
7+
8+
type PingCommand struct {
9+
serverDetails *config.ServerDetails
10+
response []byte
11+
}
12+
13+
func NewPingCommand() *PingCommand {
14+
return &PingCommand{}
15+
}
16+
17+
func (pc *PingCommand) Response() []byte {
18+
return pc.response
19+
}
20+
21+
func (pc *PingCommand) ServerDetails() (*config.ServerDetails, error) {
22+
return pc.serverDetails, nil
23+
}
24+
25+
func (pc *PingCommand) SetServerDetails(serverDetails *config.ServerDetails) *PingCommand {
26+
pc.serverDetails = serverDetails
27+
return pc
28+
}
29+
30+
func (pc *PingCommand) CommandName() string {
31+
return "rt_ping"
32+
}
33+
34+
func (pc *PingCommand) Run() error {
35+
var err error
36+
pc.response, err = pc.Ping()
37+
if err != nil {
38+
return err
39+
}
40+
return nil
41+
}
42+
43+
func (pc *PingCommand) Ping() ([]byte, error) {
44+
servicesManager, err := utils.CreateServiceManager(pc.serverDetails, -1, 0, false)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return servicesManager.Ping()
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package generic
2+
3+
import (
4+
"fmt"
5+
"github.com/stretchr/testify/assert"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
10+
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
11+
"github.com/jfrog/jfrog-cli-core/v2/utils/log"
12+
)
13+
14+
func TestPingSuccess(t *testing.T) {
15+
log.SetDefaultLogger()
16+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17+
w.WriteHeader(http.StatusOK)
18+
_, err := fmt.Fprint(w, "OK")
19+
assert.NoError(t, err)
20+
}))
21+
defer ts.Close()
22+
responseBytes, err := new(PingCommand).SetServerDetails(&config.ServerDetails{ArtifactoryUrl: ts.URL + "/"}).Ping()
23+
if err != nil {
24+
t.Logf("Error received from Artifactory following ping request: %s", err)
25+
t.Fail()
26+
}
27+
responseString := string(responseBytes)
28+
if responseString != "OK" {
29+
t.Logf("Non 'OK' response received from Artifactory following ping request:: %s", responseString)
30+
t.Fail()
31+
}
32+
}
33+
34+
func TestPingFailed(t *testing.T) {
35+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
36+
w.WriteHeader(http.StatusServiceUnavailable)
37+
_, err := fmt.Fprint(w, `{"error":"error"}`)
38+
assert.NoError(t, err)
39+
}))
40+
defer ts.Close()
41+
_, err := new(PingCommand).SetServerDetails(&config.ServerDetails{ArtifactoryUrl: ts.URL + "/"}).Ping()
42+
if err == nil {
43+
t.Log("Expected error from artifactory")
44+
t.Fail()
45+
}
46+
}

artifactory/commands/gradle/config/gradle.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

artifactory/commands/gradle/deployableArtifacts/artifacts

Lines changed: 0 additions & 1 deletion
This file was deleted.

artifactory/commands/transferconfig/transferconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/jfrog/gofrog/version"
1414

15-
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/generic"
15+
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
1616
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferconfig/configxmlutils"
1717
commandsUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
1818
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils/precheckrunner"

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require (
1414
github.com/jedib0t/go-pretty/v6 v6.6.5
1515
github.com/jfrog/build-info-go v1.10.8
1616
github.com/jfrog/gofrog v1.7.6
17-
github.com/jfrog/jfrog-cli-artifactory v0.1.11
1817
github.com/jfrog/jfrog-client-go v1.49.1
1918
github.com/magiconair/properties v1.8.9
2019
github.com/manifoldco/promptui v0.9.0
@@ -97,7 +96,7 @@ require (
9796
gopkg.in/warnings.v0 v0.1.2 // indirect
9897
)
9998

100-
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250121093504-a3e981c875d7
99+
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c
101100

102101
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd
103102

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
1919
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
2020
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
2121
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
22-
github.com/bhanurp/jfrog-cli-artifactory v0.1.12-0.20250110100951-d002779f4509 h1:UYm+G5P/YTo+Y/gOG72U3JOYqSmJc53fp8x6UtZInho=
23-
github.com/bhanurp/jfrog-cli-artifactory v0.1.12-0.20250110100951-d002779f4509/go.mod h1:2bMm7UHMiJY1DEJTLSFJyRCiR8kCwx71m/FoFJezNNo=
2422
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
2523
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
2624
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=

0 commit comments

Comments
 (0)