Skip to content

Instantly share code, notes, and snippets.

@StefMa
Created March 1, 2019 13:06
Show Gist options
  • Save StefMa/875637882da296856f37331d9b0ce2fb to your computer and use it in GitHub Desktop.
Save StefMa/875637882da296856f37331d9b0ce2fb to your computer and use it in GitHub Desktop.
Golang test basics

Golang test basics

  1. Build the Dockerfile
docker build -t go-test .
  1. Run the docker image
docker run -v ${PWD}:/go/src/app go-test
FROM golang:1.11.5-alpine3.8
WORKDIR /go/src/app
VOLUME WORKDIR
CMD ["go", "test"]
package main
func add(x int, y int) int {
return x + y
}
package main
import(
"testing"
)
func TestAddShouldReturnTheSum(t *testing.T) {
want := 4
got := add(2,2)
if want != got {
t.Errorf("%d is not %d", want, got)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment