fakesync

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fakesync is a fake sync adapter for tests of the harness side of the sync-adapter protocol (folder-sync plan §4.3, docs/sync-adapters.md): a POSIX shell script the test writes into its own temp directory and launches as `/bin/sh <script> <verb>` — an argv array, never `sh -c`, and the fresh file is READ by the shell rather than exec'd, which is what macOS's first-exec assessment and Linux's ETXTBSY need (the repository's rule for a script fixture).

The script appends one line per call to its record file — the verb, the BRIGADE_STATE_DIR it was given and its stdin request, tab-separated — and answers each verb with a canned 4.3 envelope from Answers. Nothing here ships.

Index

Constants

View Source
const (
	SelfPeer        = "SELF-DEVICE-1"
	DefaultDescribe = `{"name":"syncthing","version":"test","protocol_version":"sync/1"}`
	DefaultAttach   = `{"peer":"` + SelfPeer + `"}`
	DefaultApply    = `{"folders":[{"id":"f1","state":"idle"}],"peers":[{"peer":"P1","connected":true}]}`
	DefaultStatus   = `{"running":true,"peer":"` + SelfPeer + `","folders":[],"peers":[]}`
	DefaultDetach   = `{"stopped":true}`
)

The defaults: a sync/1 adapter named syncthing whose engine's device id is SelfPeer, one idle folder and one connected peer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answers

type Answers struct {
	Describe string
	Attach   string
	Apply    string
	Status   string
	Detach   string
	// ApplySequence, when set, is apply's result call by call: the first
	// apply answers the first entry, the second the second, and every
	// later one the last. It takes the place of Apply.
	ApplySequence []string
	// ErrorOn lists the verbs that fail.
	ErrorOn      []string
	ErrorMessage string
}

Answers are the canned results, each the raw JSON of the verb's `result` member. A zero member takes the default below; ErrorOn names verbs answered with a failing envelope (code `unavailable`, exit 9, the message ErrorMessage) instead.

type Fake

type Fake struct {
	// Argv is the argv prefix a Client runs: /bin/sh and the script.
	Argv []string
	// RecordPath is the file every call is appended to.
	RecordPath string
}

A Fake is one written script.

func Write

func Write(tb testing.TB, dir string, a Answers) *Fake

Write writes the script and its (empty) record file into dir.

func (*Fake) Records

func (f *Fake) Records(tb testing.TB) []Record

Records reads every call recorded so far, in order. A line still being appended (no newline yet) is left for the next read.

func (*Fake) Verbs

func (f *Fake) Verbs(tb testing.TB) []string

Verbs is the recorded verbs, in order.

type Record

type Record struct {
	Verb     string
	StateDir string
	Request  jsontext.Value
}

A Record is one call the script received.

Jump to

Keyboard shortcuts

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