Skip to content

Commit 9c95474

Browse files
authored
Merge pull request #211 from haydenhoang/fix-test
fix brittle api call abort request test
2 parents 28dda95 + e03a145 commit 9c95474

File tree

4 files changed

+49
-50
lines changed

4 files changed

+49
-50
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ jobs:
2727
with:
2828
go-version: '1.22'
2929

30-
31-
- name: Install dependencies
32-
run: |
33-
go mod download
34-
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
35-
36-
- name: Generate API code
37-
run: go generate ./...
38-
39-
- name: Clean module cache
40-
run: go clean -modcache
41-
4230
- name: golangci-lint
43-
uses: golangci/golangci-lint-action@v6
31+
uses: golangci/golangci-lint-action@v8
4432
with:
45-
version: v1.60
33+
version: v2.1

.golangci.yml

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1+
version: "2"
12
linters:
23
enable:
3-
- dogsled
44
- copyloopvar
5+
- dogsled
56
- funlen
67
- gocognit
78
- goconst
89
- gocritic
910
- gocyclo
10-
- gofmt
11-
- goimports
1211
- gosec
1312
- misspell
1413
- nestif
1514
- prealloc
16-
# - unconvert
17-
- unparam
1815
- revive
19-
20-
linters-settings:
21-
# govet:
22-
# enable:
23-
# - fieldalignment
24-
revive:
16+
- unparam
17+
settings:
18+
revive:
19+
rules:
20+
- name: var-naming
21+
arguments:
22+
- - ID
23+
severity: warning
24+
exclude:
25+
- ""
26+
exclusions:
27+
generated: lax
28+
presets:
29+
- comments
30+
- common-false-positives
31+
- legacy
32+
- std-error-handling
2533
rules:
26-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
27-
- name: var-naming
28-
severity: warning
29-
exclude: [""]
30-
arguments:
31-
- ["ID"] # AllowList
32-
33-
run:
34-
timeout: 3m
35-
36-
issues:
37-
exclude-rules:
38-
- linters:
39-
- gosec
40-
text: "G404"
41-
- linters:
42-
- funlen
43-
path: _test\.go
44-
- linters:
45-
- errcheck
46-
path: _test\.go
47-
34+
- linters:
35+
- gosec
36+
text: G404
37+
- linters:
38+
- funlen
39+
path: _test\.go
40+
- linters:
41+
- errcheck
42+
path: _test\.go
43+
paths:
44+
- third_party$
45+
- builtin$
46+
- examples$
47+
formatters:
48+
enable:
49+
- gofmt
50+
- goimports
51+
exclusions:
52+
generated: lax
53+
paths:
54+
- third_party$
55+
- builtin$
56+
- examples$

typesense/api_call_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ func TestApiCallCanAbortRequest(t *testing.T) {
374374
func(_ http.ResponseWriter, r *http.Request) {
375375
appendHistory(&requestURLHistory, r)
376376
cancel()
377+
// block until the client closes the connection
378+
<-r.Context().Done()
377379
},
378380
func(_ http.ResponseWriter, r *http.Request) {
379381
appendHistory(&requestURLHistory, r)

typesense/document.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (d *document[T]) Retrieve(ctx context.Context) (resp T, err error) {
2929
if err != nil {
3030
return resp, err
3131
}
32-
if !(strings.Contains(response.Header.Get("Content-Type"), "json") && response.StatusCode == 200) {
32+
if !strings.Contains(response.Header.Get("Content-Type"), "json") || response.StatusCode != 200 {
3333
body, _ := io.ReadAll(response.Body)
3434
response.Body.Close()
3535
return resp, &HTTPError{Status: response.StatusCode, Body: body}
@@ -47,7 +47,7 @@ func (d *document[T]) Update(ctx context.Context, document any, params *api.Docu
4747
if err != nil {
4848
return resp, err
4949
}
50-
if !(strings.Contains(response.Header.Get("Content-Type"), "json") && response.StatusCode == 200) {
50+
if !strings.Contains(response.Header.Get("Content-Type"), "json") || response.StatusCode != 200 {
5151
body, _ := io.ReadAll(response.Body)
5252
response.Body.Close()
5353
return resp, &HTTPError{Status: response.StatusCode, Body: body}
@@ -65,7 +65,7 @@ func (d *document[T]) Delete(ctx context.Context) (resp T, err error) {
6565
if err != nil {
6666
return resp, err
6767
}
68-
if !(strings.Contains(response.Header.Get("Content-Type"), "json") && response.StatusCode == 200) {
68+
if !strings.Contains(response.Header.Get("Content-Type"), "json") || response.StatusCode != 200 {
6969
body, _ := io.ReadAll(response.Body)
7070
response.Body.Close()
7171
return resp, &HTTPError{Status: response.StatusCode, Body: body}

0 commit comments

Comments
 (0)