Skip to content

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

Merged
merged 7 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/pr-unit-tests-1.19.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@ jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.19

- name: Run unit tests
- 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.19

- name: Display coverage test
run: go tool cover -func=coverage.out

- name: Build Go
run: go build ./...
17 changes: 0 additions & 17 deletions .github/workflows/pr-unit-tests-1.20.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/pr-unit-tests-1.22.yaml
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

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 ?


- 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 ./...
8 changes: 8 additions & 0 deletions .golangci.yml
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default: test

test:
go vet ./...
go test -v -race ./...
go test -v -race ./... -coverprofile=coverage.out

updatedeps:
go get -f -t -u ./...
Expand Down
21 changes: 17 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}()
Copy link

Choose a reason for hiding this comment

The 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 errors and see if the test needs to fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was added as a part of lint fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check on the second part in the above comment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go func() {
for err := range errors {
log.Println("Received error:", err)
}
}()
on adding this I saw that error. was being passed to the errors channel, and the test is designed to fail.


// Wait again
select {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion roundtripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func TestRoundTripper_RoundTrip(t *testing.T) {
w.WriteHeader(404)
} else {
w.WriteHeader(200)
w.Write([]byte("success!"))
if _, err := w.Write([]byte("success!")); err != nil {
t.Fatalf("failed to write: %v", err)
}
}
}))
defer ts.Close()
Expand Down