Skip to content

Commit c6f56d7

Browse files
committed
Set the timeout values from the given gitEnv
1 parent 1ba67ca commit c6f56d7

File tree

3 files changed

+64
-20
lines changed

3 files changed

+64
-20
lines changed

lfsapi/client_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package lfsapi
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestNewClient(t *testing.T) {
11+
c, err := NewClient(testEnv(map[string]string{}), testEnv(map[string]string{
12+
"lfs.dialtimeout": "151",
13+
"lfs.keepalive": "152",
14+
"lfs.tlstimeout": "153",
15+
"lfs.concurrenttransfers": "154",
16+
}))
17+
18+
require.Nil(t, err)
19+
assert.Equal(t, 151, c.DialTimeout)
20+
assert.Equal(t, 152, c.KeepaliveTimeout)
21+
assert.Equal(t, 153, c.TLSTimeout)
22+
assert.Equal(t, 154, c.ConcurrentTransfers)
23+
}

lfsapi/endpoint_finder.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,3 @@ func initAliases(e *endpointGitFinder, git env) {
264264
e.aliases[gitval] = gitkey[len(prefix) : len(gitkey)-len(suffix)]
265265
}
266266
}
267-
268-
type env interface {
269-
Get(string) (string, bool)
270-
Bool(key string, def bool) (val bool)
271-
All() map[string]string
272-
}

lfsapi/lfsapi.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net"
66
"net/http"
77
"regexp"
8+
"strconv"
89
"strings"
910
"sync"
1011
"time"
@@ -22,14 +23,13 @@ type Client struct {
2223
Credentials CredentialHelper
2324
Netrc NetrcFinder
2425

25-
DialTimeout int `git:"lfs.dialtimeout"`
26-
KeepaliveTimeout int `git:"lfs.keepalive"`
27-
TLSTimeout int `git:"lfs.tlstimeout"`
28-
ConcurrentTransfers int `git:"lfs.concurrenttransfers"`
29-
30-
HTTPSProxy string
31-
HTTPProxy string
32-
NoProxy string
26+
DialTimeout int
27+
KeepaliveTimeout int
28+
TLSTimeout int
29+
ConcurrentTransfers int
30+
HTTPSProxy string
31+
HTTPProxy string
32+
NoProxy string
3333

3434
hostClients map[string]*http.Client
3535
clientMu sync.Mutex
@@ -51,16 +51,22 @@ func NewClient(osEnv env, gitEnv env) (*Client, error) {
5151

5252
httpsProxy, httpProxy, noProxy := getProxyServers(osEnv, gitEnv)
5353

54-
return &Client{
54+
c := &Client{
5555
Endpoints: NewEndpointFinder(gitEnv),
5656
Credentials: &CommandCredentialHelper{
5757
SkipPrompt: !osEnv.Bool("GIT_TERMINAL_PROMPT", true),
5858
},
59-
Netrc: netrc,
60-
HTTPSProxy: httpsProxy,
61-
HTTPProxy: httpProxy,
62-
NoProxy: noProxy,
63-
}, nil
59+
Netrc: netrc,
60+
DialTimeout: gitEnv.Int("lfs.dialtimeout", 0),
61+
KeepaliveTimeout: gitEnv.Int("lfs.keepalive", 0),
62+
TLSTimeout: gitEnv.Int("lfs.tlstimeout", 0),
63+
ConcurrentTransfers: gitEnv.Int("lfs.concurrenttransfers", 0),
64+
HTTPSProxy: httpsProxy,
65+
HTTPProxy: httpProxy,
66+
NoProxy: noProxy,
67+
}
68+
69+
return c, nil
6470
}
6571

6672
func (c *Client) Do(req *http.Request) (*http.Response, error) {
@@ -170,6 +176,13 @@ func decodeResponse(res *http.Response, obj interface{}) error {
170176
return nil
171177
}
172178

179+
type env interface {
180+
Get(string) (string, bool)
181+
Int(string, int) int
182+
Bool(string, bool) bool
183+
All() map[string]string
184+
}
185+
173186
// basic config.Environment implementation. Only used in tests, or as a zero
174187
// value to NewClient().
175188
type testEnv map[string]string
@@ -179,6 +192,20 @@ func (e testEnv) Get(key string) (string, bool) {
179192
return v, ok
180193
}
181194

195+
func (e testEnv) Int(key string, def int) (val int) {
196+
s, _ := e.Get(key)
197+
if len(s) == 0 {
198+
return def
199+
}
200+
201+
i, err := strconv.Atoi(s)
202+
if err != nil {
203+
return def
204+
}
205+
206+
return i
207+
}
208+
182209
func (e testEnv) Bool(key string, def bool) (val bool) {
183210
s, _ := e.Get(key)
184211
if len(s) == 0 {

0 commit comments

Comments
 (0)