Help us shape the future of Go! Take the 2026 Go Developer Survey

fake

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package fake holds in-memory implementations of the services the theme engine and the site front controller consume (content, taxonomy, media, menus, redirects, seo), for tests. They are deliberately simple: slices and maps guarded by a mutex, no validation beyond what tests need.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("fake: not found")

ErrNotFound is returned by the fakes that have no package sentinel.

Functions

This section is empty.

Types

type Content

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

Content is an in-memory content.Service.

func NewContent

func NewContent() *Content

NewContent returns a store seeded with the system types post and page.

func (*Content) Add

func (c *Content) Add(it content.Item) content.Item

Add stores it (assigning an ID when empty) and returns the stored copy.

func (*Content) Create

func (c *Content) Create(_ context.Context, in content.Input) (*content.Item, error)

func (*Content) CreateTranslation

func (c *Content) CreateTranslation(context.Context, string, string) (*content.Item, error)

func (*Content) Delete

func (c *Content) Delete(_ context.Context, id string, _ bool) error

func (*Content) DeleteType

func (c *Content) DeleteType(_ context.Context, slug string) error

func (*Content) Get

func (c *Content) Get(_ context.Context, id string) (*content.Item, error)

func (*Content) GetBySlug

func (c *Content) GetBySlug(_ context.Context, typ, slug, locale string) (*content.Item, error)

GetBySlug matches locale exactly ("" matches only items without a locale).

func (*Content) GetType

func (c *Content) GetType(_ context.Context, slug string) (*content.Type, error)

func (*Content) LinkTranslation

func (c *Content) LinkTranslation(context.Context, string, string) error

func (*Content) LinkTranslationGuarded

func (c *Content) LinkTranslationGuarded(context.Context, string, string, []string) error

func (*Content) Publish

func (c *Content) Publish(_ context.Context, id string) error

func (*Content) Query

Query supports Type, Status, Search, ParentID, Locale, Taxonomy (any of the slugs), Fields (eq only), Order (published_at, title, menu_order) and paging (default 10 per page).

func (*Content) Reindex

func (c *Content) Reindex(context.Context) error

func (*Content) Restore

func (c *Content) Restore(ctx context.Context, id, _ string) (*content.Item, error)

func (*Content) Revisions

func (c *Content) Revisions(context.Context, string) ([]content.Revision, error)

func (*Content) SaveType

func (c *Content) SaveType(_ context.Context, t content.Type) error

func (*Content) Translations

func (c *Content) Translations(ctx context.Context, id string) ([]content.Item, error)

Translations returns the item alone: the fake has no translation groups.

func (*Content) Types

func (c *Content) Types(context.Context) ([]content.Type, error)

func (*Content) UnlinkTranslation

func (c *Content) UnlinkTranslation(context.Context, string) error

func (*Content) Unpublish

func (c *Content) Unpublish(_ context.Context, id string) error

func (*Content) Update

func (c *Content) Update(_ context.Context, id string, in content.Input) (*content.Item, error)

func (*Content) Validate

func (c *Content) Validate(_ *content.Type, fields map[string]any) (map[string]any, content.FieldErrors)

type Media

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

Media is an in-memory media.Service keyed by ID.

func NewMedia

func NewMedia() *Media

NewMedia returns an empty library.

func (*Media) Add

func (s *Media) Add(m media.Media)

Add stores m.

func (*Media) Delete

func (s *Media) Delete(_ context.Context, id string) error

func (*Media) FindBySourceURL

func (s *Media) FindBySourceURL(context.Context, string) (*media.Media, error)

func (*Media) FromURL

func (*Media) Get

func (s *Media) Get(_ context.Context, id string) (*media.Media, error)

func (*Media) List

func (*Media) URL

func (s *Media) URL(m *media.Media, variant string) string

func (*Media) Update

func (s *Media) Update(ctx context.Context, id string, _ media.Patch) (*media.Media, error)

func (*Media) Upload

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

Menus is an in-memory menus.Service. It does not apply the "menus.resolve_url" filter; the theme fills empty URLs itself.

func NewMenus

func NewMenus(ms ...menus.Menu) *Menus

NewMenus returns the store with the given menus.

func (s *Menus) ByLocation(_ context.Context, loc string) (*menus.Menu, error)
func (s *Menus) ByLocationLocale(ctx context.Context, loc, locale string) (*menus.Menu, error)

ByLocationLocale prefers the menu of locale, then the one for every locale.

func (s *Menus) Delete(_ context.Context, id string) error
func (s *Menus) Get(_ context.Context, slug string) (*menus.Menu, error)
func (s *Menus) List(context.Context) ([]menus.Menu, error)
func (s *Menus) Save(_ context.Context, m menus.Menu) (*menus.Menu, error)
func (s *Menus) SaveItems(context.Context, string, []menus.Item) error

type Module

type Module struct {
	Content   *Content
	Taxonomy  *Taxonomy
	Media     *Media
	Menus     *Menus
	Redirects *Redirects
	SEO       seo.Service
}

Module registers the non-nil fakes under the kernel.Service* names. Put it before theme in the module list; its name is outside kernel.BootOrder.

func NewModule

func NewModule() *Module

NewModule returns a module with every fake set (fresh, empty stores).

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module.

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (m *Module) Register(d *kernel.Deps) error

Register implements kernel.Module.

type Redirects

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

Redirects is an in-memory redirects.Service keyed by from path.

func NewRedirects

func NewRedirects(rs ...redirects.Redirect) *Redirects

NewRedirects returns the store with the given redirects.

func (*Redirects) Delete

func (s *Redirects) Delete(context.Context, string) error

func (*Redirects) Hit

func (s *Redirects) Hit(context.Context, string)

func (*Redirects) List

func (*Redirects) Lookup

func (s *Redirects) Lookup(_ context.Context, path string) (*redirects.Redirect, bool)

func (*Redirects) Save

type SEO

type SEO struct{}

SEO renders a <title> and description meta; Sitemap and Robots return fixed bodies tests can assert on.

func (SEO) Entries

func (SEO) Entries(context.Context) ([]seo.SitemapEntry, error)

func (SEO) Render

func (SEO) Render(_ context.Context, m seo.Meta, fallback seo.Meta) template.HTML

func (SEO) Robots

func (SEO) Robots(context.Context) string

func (SEO) Sitemap

func (SEO) Sitemap(context.Context) ([]byte, error)

type Taxonomy

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

Taxonomy is an in-memory taxonomy.Service seeded with category and tag.

func NewTaxonomy

func NewTaxonomy() *Taxonomy

NewTaxonomy returns the seeded store.

func (*Taxonomy) AddTerm

func (s *Taxonomy) AddTerm(t taxonomy.Term) taxonomy.Term

AddTerm stores t (ID defaults to taxonomy:slug).

func (*Taxonomy) ContentIDs

func (s *Taxonomy) ContentIDs(context.Context, string, []string) ([]string, error)

func (*Taxonomy) ContentTerms

func (s *Taxonomy) ContentTerms(context.Context, string) (map[string][]string, error)

func (*Taxonomy) Delete

func (s *Taxonomy) Delete(_ context.Context, slug string) error

func (*Taxonomy) DeleteTerm

func (s *Taxonomy) DeleteTerm(_ context.Context, id string) error

func (*Taxonomy) Get

func (s *Taxonomy) Get(_ context.Context, slug string) (*taxonomy.Taxonomy, error)

func (*Taxonomy) GetTerm

func (s *Taxonomy) GetTerm(_ context.Context, id string) (*taxonomy.Term, error)

func (*Taxonomy) GetTermBySlug

func (s *Taxonomy) GetTermBySlug(_ context.Context, tax, slug string) (*taxonomy.Term, error)

func (*Taxonomy) Save

func (*Taxonomy) SaveTerm

func (s *Taxonomy) SaveTerm(_ context.Context, t taxonomy.Term) (*taxonomy.Term, error)

func (*Taxonomy) SetContentTerms

func (s *Taxonomy) SetContentTerms(context.Context, string, map[string][]string) error

func (*Taxonomy) Taxonomies

func (s *Taxonomy) Taxonomies(context.Context) ([]taxonomy.Taxonomy, error)

func (*Taxonomy) Terms

func (s *Taxonomy) Terms(_ context.Context, tax string, _ taxonomy.TermQuery) ([]taxonomy.Term, int, error)

Jump to

Keyboard shortcuts

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