-
Notifications
You must be signed in to change notification settings - Fork 265
Build test #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build test #251
Changes from 5 commits
57872b0
df099af
cf4213f
4016ddd
a75949c
e3867e3
9c1b40b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Unit tests (Go 1.20+) | ||
on: | ||
pull_request: | ||
types: ['opened', 'synchronize'] | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | ||
with: | ||
go-version: 1.22 | ||
|
||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 | ||
|
||
- name: Run unit tests and generate coverage report | ||
run: make test | ||
|
||
- name: Upload coverage report | ||
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 | ||
with: | ||
path: coverage.out | ||
name: Coverage-report-1.20+ | ||
|
||
- name: Display coverage report | ||
run: go tool cover -func=coverage.out | ||
|
||
- name: Build Go | ||
run: go build ./... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
linters: | ||
disable-all: true | ||
enable: | ||
- errcheck | ||
- staticcheck | ||
- gosimple | ||
- govet | ||
output_format: colored-line-number |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,7 +223,14 @@ func testClientDo(t *testing.T, body interface{}) { | |
t.Fatalf("err: %v", err) | ||
} | ||
defer list.Close() | ||
go http.Serve(list, handler) | ||
errors := make(chan error) | ||
go func() { | ||
err := http.Serve(list, handler) | ||
if err != nil { | ||
errors <- err | ||
return | ||
} | ||
}() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Was this added as a fix for lint check ? Also, we should check if there were any errors added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this was added as a part of lint fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check on the second part in the above comment ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go func() { |
||
|
||
// Wait again | ||
select { | ||
|
@@ -646,10 +653,14 @@ func testClientResponseLogHook(t *testing.T, l interface{}, buf *bytes.Buffer) { | |
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if time.Now().After(passAfter) { | ||
w.WriteHeader(200) | ||
w.Write([]byte("test_200_body")) | ||
if _, err := w.Write([]byte("test_200_body")); err != nil { | ||
t.Fatalf("failed to write: %v", err) | ||
} | ||
} else { | ||
w.WriteHeader(500) | ||
w.Write([]byte("test_500_body")) | ||
if _, err := w.Write([]byte("test_500_body")); err != nil { | ||
t.Fatalf("failed to write: %v", err) | ||
} | ||
} | ||
})) | ||
defer ts.Close() | ||
|
@@ -725,7 +736,9 @@ func TestClient_NewRequestWithContext(t *testing.T) { | |
func TestClient_RequestWithContext(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(200) | ||
w.Write([]byte("test_200_body")) | ||
if _, err := w.Write([]byte("test_200_body")); err != nil { | ||
t.Fatalf("failed to write: %v", err) | ||
} | ||
})) | ||
defer ts.Close() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Both the workflows look the same to me, can you use matrix in workflow to make it a single file ?