Go 1 cheatsheet
Go 1: Testing and profiling
10 common Go 1 tasks.
Run matching tests
Run tests whose names match a regular expression, in one package.
go test -run TestLogin ./pkg/auth
View coverage in the browser
Write a coverage profile and open an annotated HTML report.
go test -coverprofile=coverage.out ./... && go tool cover -html=coverage.out
Run benchmarks
Run benchmarks and report memory allocations. Tests are skipped.
go test -bench=. -benchmem -run=^$ ./...
Fuzz a function
Run a fuzz test for 30 seconds to look for inputs that make it fail.
go test -fuzz=FuzzParse -fuzztime=30s
Profile a running service
Capture 30 seconds of CPU profile from a service that exposes net/http/pprof.
go tool pprof http://localhost:6060/debug/pprof/profile