From 703d2b8c7553dab5d4b5f7a2c80d57a11cf50121 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Thu, 21 Dec 2023 13:31:31 +0800 Subject: [PATCH 1/4] chore: fix tyop in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43d5751..53caa7f 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Then push some code to main: git checkout --orphan badges git rm -rf . rm -f .gitignore - echo 'This branch exists only to contains the coverage badge in the README on `main`.' > README.md + echo 'This branch exists only to store the coverage badge in the README on `main`.' > README.md git add README.md git commit -m 'chore: initialize the badges branch' git push origin badges @@ -101,7 +101,7 @@ Configure the repository: 1. Go to repository Settings > Rules > Rulesets, and import the `protect-default-branch.json` ruleset. -1. That's it. +That's it. ## How to contribute From 97bb8fb6431c139373ba7cb32319bee92bcb7b81 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Thu, 21 Dec 2023 13:37:44 +0800 Subject: [PATCH 2/4] fix: switch to atomic coverage counts This makes the counts accurate for parallel tests. --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 0bbabdd..45d7e0d 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -16,7 +16,7 @@ jobs: go-version: stable - name: Calculate coverage run: | - go test -v -covermode=count -coverprofile=cover.out.raw -coverpkg=./... ./... + go test -v -covermode=atomic -coverprofile=cover.out.raw -coverpkg=./... ./... # remove mocks from coverage calculation grep -v mock_ cover.out.raw > cover.out - name: Generage coverage badge From 2bb05e2b903126239b22ed105fd5c097322da1e0 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Thu, 21 Dec 2023 13:38:24 +0800 Subject: [PATCH 3/4] chore: add cover target to inspect code coverage --- .gitignore | 1 + Makefile | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 9b1c8b1..dc0c8d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /dist +/cover.out diff --git a/Makefile b/Makefile index c5dc744..64d11a6 100644 --- a/Makefile +++ b/Makefile @@ -20,3 +20,8 @@ build: .PHONY: fuzz fuzz: mod-tidy generate go test -fuzz='^Fuzz' -fuzztime=10s -v ./internal/server + +.PHONY: cover +cover: mod-tidy generate + go test -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./... + go tool cover -html=cover.out From d07ab7fc68ced591caf5e4b7c8dcee64326c9fec Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Thu, 21 Dec 2023 13:41:38 +0800 Subject: [PATCH 4/4] chore: improve test coverage --- internal/server/serve_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/server/serve_test.go b/internal/server/serve_test.go index 7de175f..0fb934f 100644 --- a/internal/server/serve_test.go +++ b/internal/server/serve_test.go @@ -47,6 +47,10 @@ func TestGreet(t *testing.T) { expect: "time travel detected", expectError: true, }, + "late birthday": { + input: []string{"Foo", "2000-12-22"}, + expect: "Hello Foo, happy belated birthday for 355 days ago.", + }, } for name, tc := range testCases { t.Run(name, func(tt *testing.T) {