From fbc67ec4bdc3f664c1d0f0e9fd95c24c991835d0 Mon Sep 17 00:00:00 2001 From: korya <148461+korya@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:23:12 -0400 Subject: [PATCH 1/5] chore: Rename module to github.com/korya/http-assert --- README.md | 6 +++--- go.mod | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7058088..61300fd 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 . ``` diff --git a/go.mod b/go.mod index c75d121..aa9c5a9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/PlanitarInc/http-assert +module github.com/korya/http-assert go 1.17 From 4c103c4f710d62842c825048c996c2261e6d6b8b Mon Sep 17 00:00:00 2001 From: korya <148461+korya@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:32:23 -0400 Subject: [PATCH 2/5] chore: Convert Makefile to Justfile --- Justfile | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 9 ------- 2 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 Justfile delete mode 100644 Makefile diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..1437933 --- /dev/null +++ b/Justfile @@ -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 + +[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 ./... \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index a644e90..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -.PHONY: pre-commit - -pre-commit: *.go - go build -o /dev/null . - go vet ./... - golangci-lint run ./... - go test ./... - go test ./... -race - go test ./... -cover From 5104dd40c947d67ffdf697a008679d67a83025ff Mon Sep 17 00:00:00 2001 From: korya <148461+korya@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:39:11 -0400 Subject: [PATCH 3/5] fix: Fix pre-commit errors --- Justfile | 2 +- main.go | 16 ++++++++-------- utils.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Justfile b/Justfile index 1437933..29ab451 100644 --- a/Justfile +++ b/Justfile @@ -11,7 +11,7 @@ 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 +pre-commit: build vet lint test test-race test-cover security [doc("Build and check compilation without creating binary")] check: diff --git a/main.go b/main.go index 053bb3e..511d881 100644 --- a/main.go +++ b/main.go @@ -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} @@ -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 { @@ -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{ @@ -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 { diff --git a/utils.go b/utils.go index 22f0dcd..5ee83a7 100644 --- a/utils.go +++ b/utils.go @@ -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 From 90383e2854e0dff4af10c76e615eca5f6d4a0ab5 Mon Sep 17 00:00:00 2001 From: korya <148461+korya@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:39:26 -0400 Subject: [PATCH 4/5] chore: Upgrade the module to GO v1.24.4 --- .github/workflows/build.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7104634..f8d43c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.17 + go-version: 1.24.4 - name: Build run: go build -v ./... diff --git a/go.mod b/go.mod index aa9c5a9..31cc090 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/korya/http-assert -go 1.17 +go 1.24.4 require ( github.com/onsi/gomega v1.17.0 From 8e7d61033b6d69d13bea209292a2b382cafe55dd Mon Sep 17 00:00:00 2001 From: korya <148461+korya@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:45:40 -0400 Subject: [PATCH 5/5] refactor: Use `just pre-commit` in CI --- .github/workflows/build.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8d43c7..58cbc79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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.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