Weekly PR #14 gometalinter vs golangci-lint and test coverage
結局、gometalinterからreviewerの一人がgolangci-lintの方が高速でいいよとのことなので、
golangci-lintを入れてみました。
forループ内の無名関数に、ループのindexを与える場合は、forループ内に閉じた変数に再代入するか、無名関数の引数に入れるかしないと
scopelintで以下のメッセージが出てfailします。引数にするのもいいのですが、型が構造体としてきちんと定義されていないと引数にできない(しづらい)ので、テストケースを大幅に変えないとならない感じでした。
fix range scope in function literal in rejson_test.go
今週はテスト系でもう1件。
goによって書かれたcache serverであるbig cacheのtest coverageを上げるPRを作成しました。
allegro.tech
go testでcoverageを見る方法はこちらです。コードのどこが通っていないかhtmlで書き出してくれます
$ go get golang.org/x/tools/cmd/cover $ go test -race -count=1 -coverprofile=server.coverprofile ./server ok github.com/allegro/bigcache/server 1.446s coverage: 64.6% of statements $ go tool cover -html=server.coverprofile -o server.html $ open server.html
あとはcoverallsのgo integrationツールgoverallsをtravis.ymlに入れればCIにも簡単に導入できます。
coveralls.io