wikifake

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package wikifake is a wikiwikibangbang that lives in a test: the routes Atlas's adapter reads, answering from pages a test writes, under an https test server.

It implements the source's contract as its ADR-0120 and its item API state it — an unreadable item is a 404, a restriction and a hold are omitted when there is none, a protected passage is a secret mark over the placeholder for a reader who may not read it, the change feed names an item the caller cannot read as "" — so the tests that use it test Atlas against the contract rather than against whatever the fake happened to answer.

Index

Constants

View Source
const Placeholder = "▒▒▒▒▒▒▒▒"

Placeholder is what a reader who may not read a passage reads.

View Source
const Token = "wiki-read-token-0123456789"

Token is the read token the fake accepts.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	ID, Name, Type string
	Data           []byte
}

Attachment is one file of a page.

type Block

type Block struct {
	Kind  string `json:"kind"`
	Text  string `json:"text,omitempty"`
	Marks []Mark `json:"marks,omitempty"`
	// Ref names an image's attachment or an embed's item; Level a heading's
	// level and Tone a panel's tone.
	Ref   string `json:"ref,omitempty"`
	Level int    `json:"level,omitempty"`
	Tone  string `json:"tone,omitempty"`
}

Block is one block of a body.

type Grant

type Grant struct {
	Space string `json:"space"`
	Role  string `json:"role"`
	Via   string `json:"via"`
}

Grant is one space role of the account.

type Mark

type Mark struct {
	Type  string `json:"type"`
	Start int    `json:"start"`
	End   int    `json:"end"`
	Href  string `json:"href,omitempty"`
	Ref   string `json:"ref,omitempty"`
}

Mark is one mark over a block's text, in runes.

type Page

type Page struct {
	ID         string
	Key        string
	Space      string
	Parent     string
	Title      string
	State      string
	Presence   string
	Version    int
	Labels     []string
	Properties map[string]any
	Body       []Block
	// ReadRestriction and EditRestriction name who may read or edit.
	ReadRestriction []string
	EditRestriction []string
	Held            bool
	// Unreadable makes the page a 404 for the account, as a restriction that
	// does not name it would.
	Unreadable bool
	// OmitPresence leaves presence out of the answer, as a source that does
	// not report it would.
	OmitPresence bool
}

Page is one item of the fake.

type Server

type Server struct {
	TS *httptest.Server

	// The account's standing.
	Scope        string
	Admin        bool
	Erasure      bool
	System       []string
	Spaces       []Grant
	RolesMissing bool
	// Down makes every request answer 503, as a source in an outage.
	Down bool
	// Redirect sends every request to another address.
	Redirect string

	// Seen records every request, "METHOD path".
	Seen []string
	// Tokens records every bearer token presented.
	Tokens []string
	// contains filtered or unexported fields
}

Server is the fake.

func New

func New() *Server

New starts a fake whose account is a read-scope viewer of space SVC.

func (*Server) Attach

func (s *Server) Attach(pageID string, a Attachment)

Attach adds a file to a page.

func (*Server) Close

func (s *Server) Close()

Close stops it.

func (*Server) Edit

func (s *Server) Edit(id string, fn func(*Page))

Edit changes a page in place, bumps its version and reports the change in the feed of whoever watches it.

func (*Server) Host

func (s *Server) Host() string

Host is its host and port.

func (*Server) Put

func (s *Server) Put(p Page)

Put adds or replaces a page; a new one is the last of its siblings.

func (*Server) Set

func (s *Server) Set(fn func(*Server))

Set runs fn under the fake's lock, for changing its standing.

func (*Server) Touch

func (s *Server) Touch(id string)

Touch writes a feed entry for a page if it is watched: its id when the account may read it, "" when it may not.

func (*Server) TouchAccount

func (s *Server) TouchAccount()

TouchAccount writes the entry the source always lists: a change to the account's own roles, which names no item.

func (*Server) URL

func (s *Server) URL() string

URL is its base address.

func (*Server) Watched

func (s *Server) Watched() []string

Watched lists the watched ids, sorted.

Jump to

Keyboard shortcuts

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