Greenfield Go multi-tenant IPFS Pinning Service wire-compatible with the
IPFS Pinning Services API spec. Paired 1:1 with Kubo over localhost RPC,
clustered via embedded NATS JetStream, Postgres source-of-truth with
RLS-enforced tenancy, Fiber + huma v2 for the HTTP surface, Authentik
OIDC for session login with kid-rotated HS256 JWT API tokens.
Feature-complete against the 22-milestone build plan, including the
ship-it v1.0 gap items:
* admin CLIs: drain/uncordon, maintenance, mint-token, rotate-key,
prune-denylist, rebalance --dry-run, cache-stats, cluster-presences
* TTL leader election via NATS KV, fence tokens, JetStream dedup
* rebalancer (plan/apply split), reconciler, requeue sweeper
* ristretto caches with NATS-backed cross-node invalidation
(placements live-nodes + token denylist)
* maintenance watchdog for stuck cluster-pause flag
* Prometheus /metrics with CIDR ACL, HTTP/pin/scheduler/cache gauges
* rate limiting: session (10/min) + anonymous global (120/min)
* integration tests: rebalance, refcount multi-org, RLS belt
* goreleaser (tar + deb/rpm/apk + Alpine Docker) targeting Gitea
Stack: Cobra/Viper, Fiber v2 + huma v2, embedded NATS JetStream,
pgx/sqlc/golang-migrate, ristretto, TypeID, prometheus/client_golang,
testcontainers-go.
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package cache_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"anchorage/internal/pkg/cache"
|
|
)
|
|
|
|
func TestCacheRoundTrip(t *testing.T) {
|
|
c, err := cache.New[string, int](cache.Options{
|
|
Name: "test",
|
|
MaxCost: 1 << 20, // 1 MiB
|
|
DefaultTTL: time.Minute,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
defer c.Close()
|
|
|
|
if !c.Set("a", 42, 1, 0) {
|
|
t.Fatal("Set returned false for fresh key")
|
|
}
|
|
c.Wait()
|
|
|
|
v, ok := c.Get("a")
|
|
if !ok {
|
|
t.Fatal("Get missed after Set")
|
|
}
|
|
if v != 42 {
|
|
t.Errorf("Get = %d, want 42", v)
|
|
}
|
|
|
|
c.Delete("a")
|
|
c.Wait()
|
|
if _, ok := c.Get("a"); ok {
|
|
t.Error("Get hit after Delete")
|
|
}
|
|
}
|
|
|
|
func TestCacheRejectsBadConfig(t *testing.T) {
|
|
_, err := cache.New[string, string](cache.Options{Name: "bad", MaxCost: 0})
|
|
if err == nil {
|
|
t.Error("expected error for MaxCost=0")
|
|
}
|
|
}
|
|
|
|
func TestNameExposed(t *testing.T) {
|
|
c, _ := cache.New[string, int](cache.Options{Name: "pin/byid", MaxCost: 1 << 16})
|
|
defer c.Close()
|
|
if c.Name() != "pin/byid" {
|
|
t.Errorf("Name = %q", c.Name())
|
|
}
|
|
}
|
|
|
|
func TestInvalidatorNilIsNoop(t *testing.T) {
|
|
var inv *cache.Invalidator
|
|
if err := inv.Emit("org", "org_xyz"); err != nil {
|
|
t.Errorf("Emit on nil Invalidator should be a no-op, got %v", err)
|
|
}
|
|
}
|