File tree Expand file tree Collapse file tree 5 files changed +38
-6
lines changed Expand file tree Collapse file tree 5 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,17 @@ commands:
15
15
type : string
16
16
platform :
17
17
type : string
18
+ govet :
19
+ type : string
20
+ default : " "
18
21
steps :
19
22
- run :
20
23
name : " Run go tests"
21
24
command : |
22
25
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
23
26
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
24
27
echo $PACKAGE_NAMES
25
- << parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_PATH/go-getter/gotestsum-report.xml -- -p 2 -cover -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
28
+ << parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_PATH/go-getter/gotestsum-report.xml -- -p 2 -cover -race -vet=<< parameters.govet >> - coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
26
29
27
30
jobs :
28
31
linux-tests :
@@ -140,6 +143,9 @@ jobs:
140
143
- run-gotests :
141
144
cmd : " ./gotestsum.exe"
142
145
platform : " win"
146
+ # Otherwise gcc is required for race detector
147
+ # See https://github.com/golang/go/issues/27089
148
+ govet : " off"
143
149
144
150
# Save coverage report parts
145
151
- persist_to_workspace :
Original file line number Diff line number Diff line change @@ -181,7 +181,6 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
181
181
if fi , err := f .Stat (); err == nil {
182
182
if _ , err = f .Seek (0 , io .SeekEnd ); err == nil {
183
183
currentFileSize = fi .Size ()
184
- req .Header .Set ("Range" , fmt .Sprintf ("bytes=%d-" , currentFileSize ))
185
184
if currentFileSize >= headResp .ContentLength {
186
185
// file already present
187
186
return nil
@@ -191,7 +190,17 @@ func (g *HttpGetter) GetFile(dst string, src *url.URL) error {
191
190
}
192
191
}
193
192
}
194
- req .Method = "GET"
193
+
194
+ req , err = http .NewRequest ("GET" , src .String (), nil )
195
+ if err != nil {
196
+ return err
197
+ }
198
+ if g .Header != nil {
199
+ req .Header = g .Header .Clone ()
200
+ }
201
+ if currentFileSize > 0 {
202
+ req .Header .Set ("Range" , fmt .Sprintf ("bytes=%d-" , currentFileSize ))
203
+ }
195
204
196
205
resp , err := g .Client .Do (req )
197
206
if err != nil {
Original file line number Diff line number Diff line change @@ -298,6 +298,23 @@ func TestHttpGetter_file(t *testing.T) {
298
298
assertContents (t , dst , "Hello\n " )
299
299
}
300
300
301
+ // TestHttpGetter_http2server tests that http.Request is not reused
302
+ // between HEAD & GET, which would lead to race condition in HTTP/2.
303
+ // This test is only meaningful for the race detector (go test -race).
304
+ func TestHttpGetter_http2server (t * testing.T ) {
305
+ g := new (HttpGetter )
306
+ src , err := url .Parse ("https://releases.hashicorp.com/terraform/0.14.0/terraform_0.14.0_SHA256SUMS" )
307
+ if err != nil {
308
+ t .Fatal (err )
309
+ }
310
+ dst := tempTestFile (t )
311
+
312
+ err = g .GetFile (dst , src )
313
+ if err != nil {
314
+ t .Fatal (err )
315
+ }
316
+ }
317
+
301
318
func TestHttpGetter_auth (t * testing.T ) {
302
319
ln := testHttpServer (t )
303
320
defer ln .Close ()
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ require (
7
7
github.com/cheggaaa/pb v1.0.27
8
8
github.com/davecgh/go-spew v1.1.1 // indirect
9
9
github.com/fatih/color v1.7.0 // indirect
10
- github.com/hashicorp/go-cleanhttp v0.5.0
10
+ github.com/hashicorp/go-cleanhttp v0.5.2
11
11
github.com/hashicorp/go-safetemp v1.0.0
12
12
github.com/hashicorp/go-version v1.1.0
13
13
github.com/klauspost/compress v1.11.2
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
42
42
github.com/googleapis/gax-go/v2 v2.0.4 /go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg =
43
43
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM =
44
44
github.com/googleapis/gax-go/v2 v2.0.5 /go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk =
45
- github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig =
46
- github.com/hashicorp/go-cleanhttp v0.5.0 /go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80 =
45
+ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ =
46
+ github.com/hashicorp/go-cleanhttp v0.5.2 /go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48 =
47
47
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo =
48
48
github.com/hashicorp/go-safetemp v1.0.0 /go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I =
49
49
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0 =
You can’t perform that action at this time.
0 commit comments