-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathartifactorycustomhttpclient_test.go
65 lines (54 loc) · 1.37 KB
/
artifactorycustomhttpclient_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tests
import (
"github.com/jfrog/jfrog-client-go/artifactory"
"github.com/jfrog/jfrog-client-go/config"
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"testing"
)
func TestGetArtifactoryVersionWithCustomHttpClient(t *testing.T) {
initArtifactoryTest(t)
rtDetails := GetRtDetails()
client := http.DefaultClient
serviceConfig, err := config.NewConfigBuilder().
SetServiceDetails(rtDetails).
SetDryRun(false).
SetHttpClient(client).
Build()
if err != nil {
t.Error(err)
}
rtManager, err := artifactory.New(serviceConfig)
if err != nil {
t.Error(err)
}
version, err := rtManager.GetVersion()
assert.NoError(t, err, "Should not fail")
if version == "" {
t.Error("Expected a version, got empty string")
}
}
func TestGetArtifactoryVersionWithProxyShouldFail(t *testing.T) {
initArtifactoryTest(t)
rtDetails := GetRtDetails()
proxyUrl, err := url.Parse("http://invalidproxy:12345")
assert.NoError(t, err)
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)},
}
serviceConfig, err := config.NewConfigBuilder().
SetServiceDetails(rtDetails).
SetDryRun(false).
SetHttpClient(client).
Build()
if err != nil {
t.Error(err)
}
rtManager, err := artifactory.New(serviceConfig)
if err != nil {
t.Error(err)
}
_, err = rtManager.GetVersion()
assert.Error(t, err, "Should fail with invalid proxy")
}