Initial project setup

main
Drew Bednar 1 month ago
parent 3f1f2a5df7
commit ffce70ad3e

@ -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

@ -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 <target> 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

@ -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

@ -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)
}

@ -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)
}
}

@ -0,0 +1,3 @@
module git.runcible.io/learning/pulley
go 1.24.1
Loading…
Cancel
Save