Core packages: crypto (Argon2id/AES-256-GCM), config (TOML/viper), db (SQLite/migrations), barrier (encrypted storage), seal (state machine with rate-limited unseal), auth (MCIAS integration with token cache), policy (priority-based ACL engine), engine (interface + registry). Server: HTTPS with TLS 1.2+, REST API, auth/admin middleware, htmx web UI (init, unseal, login, dashboard pages). CLI: cobra/viper subcommands (server, init, status, snapshot) with env var override support (METACRYPT_ prefix). Operational tooling: Dockerfile (multi-stage, non-root), docker-compose, hardened systemd units (service + daily backup timer), install script, backup script with retention pruning, production config examples. Runbook covering installation, configuration, daily operations, backup/restore, monitoring, troubleshooting, and security procedures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1000 B
Go
45 lines
1000 B
Go
package db
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestOpenAndMigrate(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test.db")
|
|
|
|
database, err := Open(path)
|
|
if err != nil {
|
|
t.Fatalf("Open: %v", err)
|
|
}
|
|
defer database.Close()
|
|
|
|
if err := Migrate(database); err != nil {
|
|
t.Fatalf("Migrate: %v", err)
|
|
}
|
|
|
|
// Verify tables exist.
|
|
tables := []string{"seal_config", "barrier_entries", "schema_migrations"}
|
|
for _, table := range tables {
|
|
var name string
|
|
err := database.QueryRow(
|
|
"SELECT name FROM sqlite_master WHERE type='table' AND name=?", table).Scan(&name)
|
|
if err != nil {
|
|
t.Errorf("table %q not found: %v", table, err)
|
|
}
|
|
}
|
|
|
|
// Migration should be idempotent.
|
|
if err := Migrate(database); err != nil {
|
|
t.Fatalf("second Migrate: %v", err)
|
|
}
|
|
|
|
// Check migration version.
|
|
var version int
|
|
database.QueryRow("SELECT MAX(version) FROM schema_migrations").Scan(&version)
|
|
if version != 1 {
|
|
t.Errorf("migration version: got %d, want 1", version)
|
|
}
|
|
}
|