testpds

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package testpds provides an in-process fake ATProto PDS for integration tests. It implements the minimal XRPC surface that AppView and Hold call during push/pull (createSession, getServiceAuth, repo.put/get/list/delete Record, identity.resolveHandle), plus an identity.Directory implementation so DID resolution short-circuits the network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

Directory is an in-memory identity.Directory containing both the user identities served by the fake PDS and any service DIDs the test registers (e.g. the Hold's did:web identity). Install via atproto.SetDirectory().

func (*Directory) Lookup

Lookup implements identity.Directory.

func (*Directory) LookupDID

func (d *Directory) LookupDID(_ context.Context, did syntax.DID) (*identity.Identity, error)

LookupDID implements identity.Directory.

func (*Directory) LookupHandle

func (d *Directory) LookupHandle(_ context.Context, handle syntax.Handle) (*identity.Identity, error)

LookupHandle implements identity.Directory.

func (*Directory) Purge

Purge implements identity.Directory. Our directory is authoritative — entries don't expire — so this is a no-op.

func (*Directory) Register

func (d *Directory) Register(ident *identity.Identity)

Register adds an identity to the directory. Callers (Server.AddIdentity or the test harness adding the hold) construct the identity.Identity and pass it in. Subsequent Lookup/LookupDID/LookupHandle calls return this entry.

type Identity

type Identity struct {
	DID         syntax.DID
	Handle      syntax.Handle
	SigningKey  *atcrypto.PrivateKeyK256
	Password    string // synthetic app-password; opaque to tests
	AccessToken string // synthetic accessJwt returned by createSession
	// contains filtered or unexported fields
}

Identity is a single account on the fake PDS. Each identity has its own K-256 signing keypair used to sign service-auth JWTs the Hold service verifies.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the fake PDS. Each test calls New(t) to spin one up, then AddIdentity() to register users. The Directory() must be passed to atproto.SetDirectory() so AppView and Hold resolve DIDs through it.

func New

func New(t *testing.T) *Server

New starts a fake PDS bound to a random port via httptest.NewServer. The server is torn down automatically via t.Cleanup. Callers should immediately install s.Directory() with atproto.SetDirectory() so DID resolution short- circuits through the in-memory store.

func (*Server) AddIdentity

func (s *Server) AddIdentity(handle string) (*Identity, error)

AddIdentity creates a new account, returns its Identity (DID, handle, signing key, synthetic password / accessJwt), and registers it in the directory so DID/handle lookups return it.

func (*Server) Directory

func (s *Server) Directory() *Directory

Directory returns the identity.Directory backing this fake PDS. Install via atproto.SetDirectory() before any DID resolution happens.

func (*Server) GetRecord

func (s *Server) GetRecord(did, collection, rkey string) (json.RawMessage, bool)

GetRecord returns the raw JSON value of a record stored in the fake PDS. Useful for tests that need to assert a downstream component wrote a record without going through the HTTP XRPC surface. Returns (nil, false) on miss.

func (*Server) URL

func (s *Server) URL() string

URL returns the fake PDS's base URL (http://127.0.0.1:NNNN).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL