diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fa396d9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + types: [opened, synchronize] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-go@v2 + with: + go-version: 1.14.12 + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Style checks + run: | + make style + if ! git diff --exit-code HEAD; then + echo + echo "*** Files are not formatted properly. See the above diff for more info." + exit 1 + fi + + - name: Unit tests + run: | + make unit-tests + + - name: Integration tests + run: | + make integration-tests diff --git a/Makefile b/Makefile index cdc29d2..a8f73ad 100644 --- a/Makefile +++ b/Makefile @@ -63,9 +63,14 @@ generate-go-srcs: dev @echo "+ $@" @go generate ./... -### UNIT TESTS +### TESTS .PHONY: unit-tests unit-tests: deps @echo "+ $@" @go test $(TESTFLAGS) ./... + +.PHONY: integration-tests +integration-tests: deps + @echo "+ $@" + @cd _integration-tests ; go test -count=1 -p 4 . diff --git a/client/ws_proxy.go b/client/ws_proxy.go index be2be5e..2c7d357 100644 --- a/client/ws_proxy.go +++ b/client/ws_proxy.go @@ -238,13 +238,13 @@ func (h *http2WebSocketProxy) ServeHTTP(w http.ResponseWriter, req *http.Request // gRPC already performs compression, so no need for WebSocket to add compression as well. CompressionMode: websocket.CompressionDisabled, }) - if resp != nil { + if resp != nil && resp.Body != nil { // Not strictly necessary because the library already replaces resp.Body with a NopCloser, // but seems too easy to miss should we switch to a different library. defer func() { _ = resp.Body.Close() }() } if err != nil { - if resp != nil { + if resp != nil && resp.Body != nil { if respErr := httputils.ExtractResponseError(resp); respErr != nil { err = fmt.Errorf("%w; response error: %v", err, respErr) }