sourcetest

import sourcetest "pocketone.dev/ext/contracts/instance/source/v1/sourcetest"

Package sourcetest is an instance.source/v1 provider for tests: a fixed list of instances that a test can change while it runs, the way an edit to a host's instances file or a control plane's update would.

src, scope := sourcetest.Scope(sourcev1.Instance{ID: "a", Hosts: []string{"a.test"}})
m := pocker.NewManager(scope, pocker.ManagerOptions{...}) // reads instance.source/v1 from scope
src.Set(sourcev1.Instance{ID: "a", Hosts: []string{"a.test"}, Dev: true}) // an upsert, seen by Watch

Source: ext/contracts/instance/source/v1/sourcetest.

Functions

ScopeOf

func ScopeOf(list ...sourcev1.Instance) *extkit.Scope

ScopeOf is Scope for a test that never changes the list.

Types

Source

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

Source is a sourcev1.Source whose instances a test sets. Changes made with Set and Delete reach every Watch.

New

func New(list ...sourcev1.Instance) *Source

New returns a source holding list.

Scope

func Scope(list ...sourcev1.Instance) (*Source, *extkit.Scope)

Scope returns a source holding list and a sealed host scope ("multisite") that provides it as instance.source/v1.

Source.Delete

func (s *Source) Delete(id string)

Delete removes the instance with id and tells every watcher.

Source.Set

func (s *Source) Set(inst sourcev1.Instance)

Set adds inst, or replaces the instance with its ID, and tells every watcher.

Source.Snapshot

func (s *Source) Snapshot(context.Context) ([]sourcev1.Instance, error)

Snapshot implements sourcev1.Source.

Source.Watch

func (s *Source) Watch(ctx context.Context) (<-chan sourcev1.Change, error)

Watch implements sourcev1.Source: the changes made after it, until ctx is done.