Files
cole-maxwell1 1382c42803 feat: add Hetzner-hosted todo application stack
Implement the server-rendered Go todo application with PostgreSQL persistence, Tailwind styling, health checks, and test coverage.

Provision production and staging infrastructure with OpenTofu, including private networking, static IPs, Object Storage backups, and load balancing.

Configure Rocky Linux hosts with Ansible, rootless Podman, PostgreSQL, WAL-G backup automation, staging restores, and generated inventory.
2026-08-06 21:34:56 -05:00

58 lines
1.2 KiB
Go

package db
import (
"context"
"os"
"strconv"
"testing"
"time"
)
func TestStoreLifecycle(t *testing.T) {
databaseURL := os.Getenv("TEST_DATABASE_URL")
if databaseURL == "" {
t.Skip("TEST_DATABASE_URL is not set")
}
store, err := Open(databaseURL)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = store.Close() })
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
title := "store-test-" + strconv.FormatInt(time.Now().UnixNano(), 10)
if err := store.Create(ctx, title); err != nil {
t.Fatal(err)
}
todos, err := store.List(ctx)
if err != nil {
t.Fatal(err)
}
var id int64
for _, todo := range todos {
if todo.Title == title {
id = todo.ID
break
}
}
if id == 0 {
t.Fatalf("created todo %q not found", title)
}
t.Cleanup(func() { _, _ = store.Delete(context.Background(), id) })
found, err := store.Toggle(ctx, id)
if err != nil || !found {
t.Fatalf("toggle found = %v, error = %v", found, err)
}
found, err = store.Delete(ctx, id)
if err != nil || !found {
t.Fatalf("delete found = %v, error = %v", found, err)
}
found, err = store.Delete(ctx, id)
if err != nil || found {
t.Fatalf("second delete found = %v, error = %v", found, err)
}
}