-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github.com/mccutchen/go-httpbin/main' i…
…nto relative-doc-links
- Loading branch information
Showing
29 changed files
with
3,612 additions
and
1,774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.git | ||
.* | ||
dist | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
.* | ||
*.exe | ||
*.test | ||
*.prof | ||
|
||
dist/* | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Development | ||
|
||
## Local development | ||
|
||
For interactive local development, use `make run` to build and run go-httpbin | ||
or `make watch` to automatically re-build and re-run go-httpbin on every | ||
change: | ||
|
||
make run | ||
make watch | ||
|
||
By default, the server will listen on `http://127.0.0.1:8080`, but the host, | ||
port, or any other [configuration option][config] may be overridden by | ||
specifying the relevant environment variables: | ||
|
||
make run PORT=9999 | ||
make run PORT=9999 MAX_DURATION=60s | ||
make watch HOST=0.0.0.0 PORT=8888 | ||
|
||
## Testing | ||
|
||
Run `make test` to run unit tests, using `TEST_ARGS` to pass arguments through | ||
to `go test`: | ||
|
||
make test | ||
make test TEST_ARGS="-v -race -run ^TestDelay" | ||
|
||
### Integration tests | ||
|
||
go-httpbin includes its own minimal WebSocket echo server implementation, and | ||
we use the incredibly helpful [Autobahn Testsuite][] to ensure that the | ||
implementation conforms to the spec. | ||
|
||
These tests can be slow to run (~40 seconds on my machine), so they are not run | ||
by default when using `make test`. | ||
|
||
They are run automatically as part of our extended "CI" test suite, which is | ||
run on every pull request: | ||
|
||
make testci | ||
|
||
### WebSocket development | ||
|
||
When working on the WebSocket implementation, it can also be useful to run | ||
those integration tests directly, like so: | ||
|
||
make testautobahn | ||
|
||
Use the `AUTOBAHN_CASES` var to run a specific subset of the Autobahn tests, | ||
which may or may not include wildcards: | ||
|
||
make testautobahn AUTOBAHN_CASES=6.* | ||
make testautobahn AUTOBAHN_CASES=6.5.* | ||
make testautobahn AUTOBAHN_CASES=6.5.4 | ||
|
||
|
||
### Test coverage | ||
|
||
We use [Codecov][] to measure and track test coverage as part of our continuous | ||
integration test suite. While we strive for as much coverage as possible and | ||
the Codecov CI check is configured with fairly strict requirements, 100% test | ||
coverage is not an explicit goal or requirement for all contributions. | ||
|
||
To view test coverage locally, use | ||
|
||
make testcover | ||
|
||
which will run the full suite of unit and integration tests and pop open a web | ||
browser to view coverage results. | ||
|
||
|
||
## Linting and code style | ||
|
||
Run `make lint` to run our suite of linters and formatters, which include | ||
gofmt, [revive][], and [staticcheck][]: | ||
|
||
make lint | ||
|
||
|
||
## Docker images | ||
|
||
To build a docker image locally: | ||
|
||
make image | ||
|
||
To build a docker image an push it to a remote repository: | ||
|
||
make imagepush | ||
|
||
By default, images will be tagged as `mccutchen/go-httpbin:${COMMIT}` with the | ||
current HEAD commit hash. | ||
|
||
Use `VERSION` to override the tag value | ||
|
||
make imagepush VERSION=v1.2.3 | ||
|
||
or `DOCKER_TAG` to override the remote repo and version at once: | ||
|
||
make imagepush DOCKER_TAG=my-org/my-fork:v1.2.3 | ||
|
||
### Automated docker image builds | ||
|
||
When a new release is created, the [Release][] GitHub Actions workflow | ||
automatically builds and pushes new Docker images for both linux/amd64 and | ||
linux/arm64 architectures. | ||
|
||
|
||
[config]: /README.md#configuration | ||
[revive]: https://github.com/mgechev/revive | ||
[staticcheck]: https://staticcheck.dev/ | ||
[Release]: /.github/workflows/release.yaml | ||
[Codecov]: https://app.codecov.io/gh/mccutchen/go-httpbin | ||
[Autobahn Testsuite]: https://github.com/crossbario/autobahn-testsuite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,14 @@ COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH) | |
TEST_ARGS ?= -race | ||
|
||
# 3rd party tools | ||
GOLINT := go run golang.org/x/lint/golint@latest | ||
LINT := go run github.com/mgechev/[email protected] | ||
REFLEX := go run github.com/cespare/[email protected] | ||
STATICCHECK := go run honnef.co/go/tools/cmd/[email protected] | ||
|
||
# Host and port to use when running locally via `make run` or `make watch` | ||
HOST ?= 127.0.0.1 | ||
PORT ?= 8080 | ||
|
||
|
||
# ============================================================================= | ||
# build | ||
|
@@ -34,7 +38,7 @@ buildtests: | |
.PHONY: buildtests | ||
|
||
clean: | ||
rm -rf $(DIST_PATH) $(COVERAGE_PATH) | ||
rm -rf $(DIST_PATH) $(COVERAGE_PATH) .integrationtests | ||
.PHONY: clean | ||
|
||
|
||
|
@@ -45,23 +49,26 @@ test: | |
go test $(TEST_ARGS) ./... | ||
.PHONY: test | ||
|
||
|
||
# Test command to run for continuous integration, which includes code coverage | ||
# based on codecov.io's documentation: | ||
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md | ||
testci: build buildexamples | ||
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./... | ||
git diff --exit-code | ||
AUTOBAHN_TESTS=1 go test $(TEST_ARGS) $(COVERAGE_ARGS) ./... | ||
.PHONY: testci | ||
|
||
testcover: testci | ||
go tool cover -html=$(COVERAGE_PATH) | ||
.PHONY: testcover | ||
|
||
# Run the autobahn fuzzingclient test suite | ||
testautobahn: | ||
AUTOBAHN_TESTS=1 AUTOBAHN_OPEN_REPORT=1 go test -v -run ^TestWebSocketServer$$ $(TEST_ARGS) ./... | ||
.PHONY: autobahntests | ||
|
||
lint: | ||
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1) | ||
go vet ./... | ||
$(GOLINT) -set_exit_status ./... | ||
$(LINT) -set_exit_status ./... | ||
$(STATICCHECK) ./... | ||
.PHONY: lint | ||
|
||
|
@@ -70,7 +77,7 @@ lint: | |
# run locally | ||
# ============================================================================= | ||
run: build | ||
$(DIST_PATH)/go-httpbin | ||
HOST=$(HOST) PORT=$(PORT) $(DIST_PATH)/go-httpbin | ||
.PHONY: run | ||
|
||
watch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package main implements the go-httpbin command line tool. | ||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package main demonstrates how to instrument httpbin with custom metrics. | ||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/mccutchen/go-httpbin/v2 | ||
|
||
go 1.16 | ||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package httpbin provides a simple HTTP request and response testing server, | ||
// modeled on the original httpbin.org Python project. | ||
package httpbin |
Oops, something went wrong.