diff --git a/.drone.yaml b/.drone.yaml new file mode 100644 index 0000000..6f59068 --- /dev/null +++ b/.drone.yaml @@ -0,0 +1,15 @@ +kind: pipeline +type: docker +name: CI Test Pipeline + +steps: +- name: Unit Tests + image: golang:1.24 + privileged: true + commands: + - go test -v ./... + +trigger: + event: + - pull_request + - push diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..53d346f --- /dev/null +++ b/Makefile @@ -0,0 +1,69 @@ +SQL_DATABASE?=./pulley.db +COVER_PROFILE?=./tmp/profile.out + +# TODO maybe only use -race in an ARG for CI +FLAGS := -race -v + +# `make ARGS=no-cache` will avoid using cached results in go test. +ifeq ($(ARGS), no-cache) + FLAGS += -count=1 +endif + +# make test ARGS=no-cache +test: + go test $(FLAGS) ./... +.PHONY: test + +test-short: + go test -short $(FLAGS) ./... +.PHONY: test-short + +# make test-int ARGS=no-cache +test-int: + go test $(FLAGS) ./cmd/... +.PHONY: test-int + + +## Coverage See also -covermode=count and -covermode=atomic +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/api/main.go +.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 + +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: + @echo "Checking system dependencies..." + @command -v air > /dev/null || (echo "Missing air command. go install github.com/air-verse/air@latest"; exit 1) + @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 diff --git a/air.toml b/air.toml new file mode 100644 index 0000000..06a597c --- /dev/null +++ b/air.toml @@ -0,0 +1,52 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = ["-logging=DEBUG"] + bin = "./tmp/main" + cmd = "go build -o ./tmp/main cmd/api/main.go" + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html", "go.tmpl"] + include_file = [] + kill_delay = "1s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = true + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + silent = false + time = false + +[misc] + clean_on_exit = false + +[proxy] + app_port = 0 + enabled = false + proxy_port = 0 + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/cmd/api/main.go b/cmd/api/main.go new file mode 100644 index 0000000..e2c27e7 --- /dev/null +++ b/cmd/api/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "io" + "os" +) + +func Run(w io.Writer) { + fmt.Fprint(w, "Hello API\n") +} + +func main() { + Run(os.Stdout) +} diff --git a/cmd/api/main_test.go b/cmd/api/main_test.go new file mode 100644 index 0000000..f1e8ded --- /dev/null +++ b/cmd/api/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "bytes" + "testing" +) + +func TestRun(t *testing.T) { + buffer := bytes.Buffer{} + Run(&buffer) + got := buffer.String() + want := "Hello API\n" + if got != want { + t.Errorf("got %q, want %q", got, want) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..745b553 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.runcible.io/learning/pulley + +go 1.24.1 diff --git a/internal/.gitkeep b/internal/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/.gitkeep b/migrations/.gitkeep new file mode 100644 index 0000000..e69de29