af9f331781
Minimal Go service: /healthz + /v1/tenants/by-slug/:slug + /v1/tenants/:id with an in-memory store seeded with the acme tenant. Stdlib-only; pgx + JWT validation land in M4.1 follow-up.
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestMemory_seededAcme(t *testing.T) {
|
|
m := NewMemory()
|
|
ctx := context.Background()
|
|
|
|
t.Run("by slug returns seed", func(t *testing.T) {
|
|
got, err := m.BySlug(ctx, "acme")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Slug != "acme" {
|
|
t.Errorf("slug = %q, want acme", got.Slug)
|
|
}
|
|
if got.Status != "active" {
|
|
t.Errorf("status = %q, want active", got.Status)
|
|
}
|
|
if len(got.Products) != 2 {
|
|
t.Errorf("products = %v, want [certifai compliance]", got.Products)
|
|
}
|
|
})
|
|
|
|
t.Run("by id returns seed", func(t *testing.T) {
|
|
got, err := m.ByID(ctx, "00000000-0000-0000-0000-000000000001")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Slug != "acme" {
|
|
t.Errorf("slug = %q, want acme", got.Slug)
|
|
}
|
|
})
|
|
|
|
t.Run("missing slug returns ErrNotFound", func(t *testing.T) {
|
|
_, err := m.BySlug(ctx, "nope")
|
|
if !errors.Is(err, ErrNotFound) {
|
|
t.Errorf("err = %v, want ErrNotFound", err)
|
|
}
|
|
})
|
|
|
|
t.Run("missing id returns ErrNotFound", func(t *testing.T) {
|
|
_, err := m.ByID(ctx, "deadbeef")
|
|
if !errors.Is(err, ErrNotFound) {
|
|
t.Errorf("err = %v, want ErrNotFound", err)
|
|
}
|
|
})
|
|
|
|
t.Run("returned tenant is a copy, not the stored pointer", func(t *testing.T) {
|
|
got, err := m.BySlug(ctx, "acme")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got.Name = "mutated"
|
|
got2, _ := m.BySlug(ctx, "acme")
|
|
if got2.Name == "mutated" {
|
|
t.Error("store leaked internal pointer; caller could mutate seeded state")
|
|
}
|
|
})
|
|
}
|