lets-go

module
v0.0.0-...-38c60a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2022 License: MIT

README

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
Terminate test immediately after the first test failure:
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/

Directories

Path Synopsis
cmd
web
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL