lets-go
Example and exercises from the the Book Let's Go
Generate self-signed TLS
Create tls
folder in the project's root:
mkdir tls && cd tls
Generate private key and TLS certificate:
go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost
Testing
Run all tests in the project
go test ./...
Run specific test
using run
flag
go test -v -run="^TestPing$" ./cmd/web/
To limit testing to a specific sub-tests
go test -v -run="^TestHumanDate$/^UTC$" ./cmd/web
Run tests without caching
go test -count=1 ./cmd/web
-count=1
flag means how many times to execute each test
clean the cache results:
go clean testcache
go test -failfast ./cmd/web
stops tests only in the package that had the failure.
Run tests in parallel:
func TestPing(t *testing.T) {
t.Parallel()
...
}
- Tests marked by
t.Parallel()
will be run in parallel ONLY with other parallel tests
- the maximum amount of parallel tests if the current value of
GOMAXPROCS
increase amount of parallel tests:
go test -parallel 4 ./...
Run tests with Race detector
go test -race ./cmd/web/