Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.24.4

- name: Build
run: go build -v ./...
- name: Install just
uses: extractions/setup-just@v3

- name: Vet
run: go vet -v ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- name: Install golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest

- name: Test
run: go test -v ./...
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run pre-commit checks
run: just pre-commit
81 changes: 81 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[doc("Display available commands")]
default:
@just --list

[doc("Build the binary")]
build:
go build -o http-assert .

[doc("Build for release (optimized)")]
build-release:
go build -ldflags="-s -w" -o http-assert .

[doc("Run all pre-commit checks")]
pre-commit: build vet lint test test-race test-cover security

[doc("Build and check compilation without creating binary")]
check:
go build -o /dev/null .

[doc("Run go vet")]
vet:
go vet ./...

[doc("Run golangci-lint")]
lint:
golangci-lint run ./...

[doc("Run tests")]
test:
go test ./...

[doc("Run tests with race detection")]
test-race:
go test ./... -race

[doc("Run tests with coverage")]
test-cover:
go test ./... -cover

[doc("Run tests with coverage and generate HTML report")]
test-coverage:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"

[doc("Clean build artifacts")]
clean:
rm -f http-assert coverage.out coverage.html

[doc("Install the binary to $GOPATH/bin")]
install:
go install .

[doc("Format Go code")]
fmt:
go fmt ./...

[doc("Update dependencies")]
deps-update:
go get -u ./...
go mod tidy

[doc("Download dependencies")]
deps-download:
go mod download

[doc("Run a quick development cycle")]
dev: fmt vet test

[doc("Show Go version and environment")]
info:
@echo "Go version:"
@go version
@echo "\nGo environment:"
@go env GOOS GOARCH
@echo "\nModule info:"
@go list -m

[doc("Run security scan with gosec (if installed)")]
security:
gosec ./...
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# http-assert ![Github Actions](https://github.com/PlanitarInc/http-assert/actions/workflows/build.yml/badge.svg) [![Go Reference](https://pkg.go.dev/badge/github.com/PlanitarInc/http-assert.svg)](https://pkg.go.dev/github.com/PlanitarInc/http-assert)
# http-assert ![Github Actions](https://github.com/korya/http-assert/actions/workflows/build.yml/badge.svg) [![Go Reference](https://pkg.go.dev/badge/github.com/korya/http-assert.svg)](https://pkg.go.dev/github.com/korya/http-assert)

A command-line tool for performing HTTP requests and asserting properties of the response. This tool is designed for testing HTTP endpoints, health checks, monitoring, and CI/CD pipelines.

Expand All @@ -17,13 +17,13 @@ A command-line tool for performing HTTP requests and asserting properties of the
### From Source

```bash
go install github.com/PlanitarInc/http-assert@latest
go install github.com/korya/http-assert@latest
```

### Build from Repository

```bash
git clone https://github.com/PlanitarInc/http-assert.git
git clone https://github.com/korya/http-assert.git
cd http-assert
go build -o http-assert .
```
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/PlanitarInc/http-assert
module github.com/korya/http-assert

go 1.17
go 1.24.4

require (
github.com/onsi/gomega v1.17.0
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c Client) Do(req *http.Request, assertions ...Assertion) error {
c.writeHttpDetails(&b, req, nil)
return errors.New(b.String())
}
defer res.Body.Close()
defer func() { _ = res.Body.Close() }()

c.logInfo("[:] %s %s\n", res.Proto, res.Status)
httpRes := &httpResponse{Response: res}
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c Client) Do(req *http.Request, assertions ...Assertion) error {
}

func (c Client) writeHttpDetails(w io.Writer, req *http.Request, res *httpResponse) {
fmt.Fprintf(w, "\nFAILED: %s %s (%s)\n\n", req.Method, req.URL, req.Proto)
_, _ = fmt.Fprintf(w, "\nFAILED: %s %s (%s)\n\n", req.Method, req.URL, req.Proto)
_ = req.Write(w)
_, _ = w.Write([]byte("\n\n"))
if res != nil {
Expand All @@ -356,7 +356,7 @@ func (c Client) getHttpClient() *http.Client {
},
}
if c.SkipSslChecks {
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} // #nosec G402 - user askef for it
}

return &http.Client{
Expand Down Expand Up @@ -414,19 +414,19 @@ type httpResponse struct {

func (r httpResponse) writeTo(w io.Writer, withBody bool) {
// Ensure to close previous body
b := r.Response.Body
defer b.Close()
b := r.Body
defer func() { _ = b.Close() }()
if withBody {
var b bytes.Buffer
croppedBytes := printPayload(&b, r.BodyBytes, 256)
if croppedBytes > 0 {
fmt.Fprintf(&b, "\n\n << Payload is cropped: %d bytes are hidden >>", croppedBytes)
}
r.Response.Body = io.NopCloser(&b)
r.Body = io.NopCloser(&b)
} else {
r.Response.Body = io.NopCloser(strings.NewReader(" << Payload is omitted >>"))
r.Body = io.NopCloser(strings.NewReader(" << Payload is omitted >>"))
}
_ = r.Response.Write(w)
_ = r.Write(w)
}

type hostMapping struct {
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func printPayload(w io.Writer, bs []byte, maxSize int) (croppedBytes int) {
_, _ = w.Write(bs)
} else {
d := hex.Dumper(w)
defer d.Close()
defer func() { _ = d.Close() }()
_, _ = d.Write(bs)
}
return
Expand Down