Skip to content

Commit

Permalink
Adding macos and windows to github actions #413 (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSchl8 authored Oct 1, 2023
1 parent 52f5847 commit 4d77424
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 115 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: build

on:
workflow_dispatch:
pull_request:
branches:
- master
- v*

push:
branches:
- master
Expand All @@ -15,21 +15,21 @@ on:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
go: [1.17, 1.x]

name: Go ${{ matrix.go }}
go: [1.x]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Go ${{ matrix.go }} ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4.0.1
with:
go-version: ${{ matrix.go }}
cache: true

- name: Build
run: go get -v ./...
Expand All @@ -38,17 +38,21 @@ jobs:
run: go test ./...

examples:
runs-on: ubuntu-latest

name: Examples
strategy:
matrix:
go: [1.x]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Examples ${{ matrix.go }} ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4.0.1
with:
go-version: 1.x
go-version: ${{ matrix.go }}
cache: true

- name: Build
run: cd _examples && go get -v .
Expand Down Expand Up @@ -104,12 +108,13 @@ jobs:
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4.0.1
with:
go-version: 1.x

- name: Run linters
uses: golangci/golangci-lint-action@v3
timeout-minutes: 5
with:
version: v1.51.2
working-directory: ${{ matrix.dir }}
Expand All @@ -124,9 +129,10 @@ jobs:
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4.0.1
with:
go-version: 1.x
cache: true

- name: Run tests
run: go test -covermode=count -coverprofile=coverage.out -coverpkg=. ./...
Expand Down
10 changes: 5 additions & 5 deletions binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -78,7 +78,7 @@ func (binder Binder) RoundTrip(origReq *http.Request) (*http.Response, error) {
}

if recorder.Body != nil {
resp.Body = ioutil.NopCloser(recorder.Body)
resp.Body = io.NopCloser(recorder.Body)
}

return &resp, nil
Expand Down Expand Up @@ -148,7 +148,7 @@ func (binder FastBinder) RoundTrip(stdreq *http.Request) (*http.Response, error)
}

if stdreq.Body != nil {
b, err := ioutil.ReadAll(stdreq.Body)
b, err := io.ReadAll(stdreq.Body)
if err == nil {
ctx.Request.SetBody(b)
}
Expand Down Expand Up @@ -219,9 +219,9 @@ func fast2std(stdreq *http.Request, fastresp *fasthttp.Response) *http.Response
}

if body != nil {
stdresp.Body = ioutil.NopCloser(bytes.NewReader(body))
stdresp.Body = io.NopCloser(bytes.NewReader(body))
} else {
stdresp.Body = ioutil.NopCloser(bytes.NewReader(nil))
stdresp.Body = io.NopCloser(bytes.NewReader(nil))
}

return stdresp
Expand Down
14 changes: 7 additions & 7 deletions binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httpexpect
import (
"bufio"
"crypto/tls"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand All @@ -20,7 +20,7 @@ type mockHandler struct {
}

func (c *mockHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
assert.True(c.t, err == nil)

if c.http10 {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestBinder_Basic(t *testing.T) {
"Content-Type": {"application/json"},
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestFastBinder_Basic(t *testing.T) {
"Content-Type": {"application/json"},
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestFastBinder_RemoteAddr(t *testing.T) {
t.Fatal(err)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestFastBinder_Protocol(t *testing.T) {
t.Fatal(err)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestFastBinder_EmptyResponse(t *testing.T) {

assert.False(t, resp.Body == nil)

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions body_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"runtime"
"sync"
)
Expand Down Expand Up @@ -178,7 +177,7 @@ func (bw *bodyWrapper) GetBody() (io.ReadCloser, error) {
}

// Return fresh reader for memory chunk.
return ioutil.NopCloser(bytes.NewReader(bw.memBytes)), nil
return io.NopCloser(bytes.NewReader(bw.memBytes)), nil
}

// Disables storing body contents in memory and clears the cache.
Expand Down Expand Up @@ -223,7 +222,7 @@ func (bw *bodyWrapper) httpReadNext(p []byte) (int, error) {
}

func (bw *bodyWrapper) httpReadFull() error {
b, err := ioutil.ReadAll(bw.httpReader)
b, err := io.ReadAll(bw.httpReader)

// Switch to reading from memory.
bw.isFullyRead = true
Expand Down
7 changes: 3 additions & 4 deletions body_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -152,11 +151,11 @@ func TestBodyWrapper_GetBody(t *testing.T) {
rd2, err := wrp.GetBody()
assert.NoError(t, err)

b, err := ioutil.ReadAll(rd1)
b, err := io.ReadAll(rd1)
assert.NoError(t, err)
assert.Equal(t, "test_body", string(b))

b, err = ioutil.ReadAll(rd2)
b, err = io.ReadAll(rd2)
assert.NoError(t, err)
assert.Equal(t, "test_body", string(b))

Expand Down Expand Up @@ -601,7 +600,7 @@ func TestBodyWrapper_Memory(t *testing.T) {
assert.Equal(t, 1, body.eofCount)

// check body
c, err := ioutil.ReadAll(reader)
c, err := io.ReadAll(reader)
assert.NoError(t, err)
assert.Equal(t, "123456789", string(c))

Expand Down
5 changes: 2 additions & 3 deletions e2e/fs_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"io/ioutil"
"net/http"
"os"
"path"
Expand All @@ -12,13 +11,13 @@ import (
)

func TestE2EFs_FastBinder(t *testing.T) {
tempdir, err := ioutil.TempDir("", "httpexpect")
tempdir, err := os.MkdirTemp("", "httpexpect")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempdir)

if err := ioutil.WriteFile(
if err := os.WriteFile(
path.Join(tempdir, "hello"), []byte("hello, world!"), 0666); err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/printer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package e2e

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -19,14 +19,14 @@ type mockPrinter struct {

func (p *mockPrinter) Request(req *http.Request) {
if req.Body != nil {
p.reqBody, _ = ioutil.ReadAll(req.Body)
p.reqBody, _ = io.ReadAll(req.Body)
req.Body.Close()
}
}

func (p *mockPrinter) Response(resp *http.Response, rtt time.Duration) {
if resp.Body != nil {
p.respBody, _ = ioutil.ReadAll(resp.Body)
p.respBody, _ = io.ReadAll(resp.Body)
resp.Body.Close()
}
p.rtt = rtt
Expand All @@ -36,7 +36,7 @@ func createPrinterHandler() http.Handler {
mux := http.NewServeMux()

mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
if string(body) != "test_request" {
panic("unexpected request body " + string(body))
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/redirect_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package e2e

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -18,7 +18,7 @@ func createRedirectHandler() http.Handler {
if r.Method == "GET" {
_, _ = w.Write([]byte(`default_response`))
} else {
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)
_, _ = w.Write(b)
}
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/retry_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package e2e

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"sync"
Expand Down Expand Up @@ -75,7 +75,7 @@ func createRetryHandler(rc *retryController) http.Handler {
mux := http.NewServeMux()

mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)

w.WriteHeader(rc.getStatus())
_, _ = w.Write(b)
Expand Down
6 changes: 3 additions & 3 deletions printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httpexpect
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -33,7 +33,7 @@ func TestPrinter_Compact(t *testing.T) {
printer.Request(req2)
printer.Request(nil)

printer.Response(&http.Response{Body: ioutil.NopCloser(body2)}, 0)
printer.Response(&http.Response{Body: io.NopCloser(body2)}, 0)
printer.Response(&http.Response{}, 0)
printer.Response(nil, 0)
}
Expand All @@ -51,7 +51,7 @@ func TestPrinter_Debug(t *testing.T) {
printer.Request(req2)
printer.Request(nil)

printer.Response(&http.Response{Body: ioutil.NopCloser(body2)}, 0)
printer.Response(&http.Response{Body: io.NopCloser(body2)}, 0)
printer.Response(&http.Response{}, 0)
printer.Response(nil, 0)
}
Expand Down
Loading

0 comments on commit 4d77424

Please sign in to comment.