package store import ( "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/guard" ) func TestAGuardPolicyIsAttachedOnceAndDetached(t *testing.T) { db := capacityStore(t) ctx := t.Context() a := guard.Attachment{Scope: "project", ScopeID: "p1", Policy: "finance"} for range 2 { if err := db.AttachGuard(ctx, a, "ilker"); err != nil { t.Fatal(err) } } if got, err := db.GuardAttachments(ctx); err != nil || len(got) != 1 || got[0] != a { t.Fatalf("%v %v", got, err) } if ok, err := db.DetachGuard(ctx, a); !ok || err != nil { t.Errorf("detach: %v %v", ok, err) } if ok, _ := db.DetachGuard(ctx, a); ok { t.Error("detached twice") } }