From 57584c26239c6b942b2bbc66c2cb050d2f1c579f Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Tue, 25 Feb 2025 16:44:25 -0500 Subject: [PATCH] Add some coverage commands --- Makefile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c04feba..ebbf9be 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ SQL_DATABASE?=./ratchet.db +COVER_PROFILE?=./tmp/profile.out # TODO maybe only use -race in an ARG for CI FLAGS := -race -v @@ -11,34 +12,50 @@ endif # make test ARGS=no-cache test: go test $(FLAGS) ./... -PHONEY: test +.PHONY: test test-short: go test -short $(FLAGS) ./... -PHONEY: test-short +.PHONY: test-short # make test-int ARGS=no-cache test-int: go test $(FLAGS) ./cmd/... .PHONY: test-int +cover-html: test-cover + go tool cover -html=$(COVER_PROFILE) +.PHONY:cover-html + +coverage: test-cover + go tool cover -func=$(COVER_PROFILE) +.PHONY: coverage + +test-cover: + go test -coverprofile=$(COVER_PROFILE) $(FLAGS) ./... +.PHONY: test-cover + serve: go run ./cmd/ratchetd/main.go -PHONEY: serve +.PHONY: serve # SQLite Commands sql-cli: sqlite3 $(SQL_DATABASE) -cmd ".headers on" -cmd ".mode box" -cmd ".tables" +.PHONY: sql-cli init-db: run-migrate sqlite3 $(SQL_DATABASE) "PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;" +.PHONY: init-db seed-db: sqlite3 $(SQL_DATABASE) "INSERT INTO snippets (title, content, expires_at) VALUES ('placeholder', 'placeholder content', datetime('now', '+6 months'));" +.PHONY: seed-db run-migrate: migrate -database sqlite3://$(SQL_DATABASE) -path ./migrations up +.PHONY: run-migrate # Checks system dependencies needed to run the local dev environment check-system-deps: @@ -47,8 +64,9 @@ check-system-deps: @command -v sqlite3 > /dev/null || (echo "Missing sqlite3 command. brew install sqlite"; exit 1) @command -v migrate > /dev/null || (echo "Missing migrate command. go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest"; exit 1) @echo "System dependencies fulfilled 👍" - +.PHONY: check-system-deps # Certs local-certs: cd ./tls && go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost +.PHONY: local-certs \ No newline at end of file