remotetest

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remotetest is an in-memory ZenNotes server for tests: the note routes a read, change and write needs, with or without conditional note writes (znserver supportsConditionalNoteWrites).

Index

Constants

View Source
const BinaryEnv = "ZENNOTES_SERVER_CONTRACT_BINARY"

BinaryEnv names a ZenNotes server binary for the tests that run against a real server; CI's server-contract job sets it from the server's main.

Variables

This section is empty.

Functions

func Sha256

func Sha256(body string) string

Sha256 is the hash the server hands out for body.

func StartBinary

func StartBinary(t testing.TB, binary, vaultRoot, token string) string

StartBinary runs the server binary on loopback over vaultRoot, with its configuration in a temporary directory and token as its auth token, and returns its base URL once it answers. The process stops with the test.

Types

type Proxy

type Proxy struct {
	*httptest.Server

	BeforeWrite func()
	// contains filtered or unexported fields
}

Proxy forwards to a server and runs BeforeWrite before it forwards each note write, for a test to land another client's save in between a read and the write that follows it.

func NewProxy

func NewProxy(t testing.TB, base string) *Proxy

NewProxy fronts base and stops with the test.

func (*Proxy) SetBeforeWrite

func (p *Proxy) SetBeforeWrite(hook func())

SetBeforeWrite replaces the hook.

func (*Proxy) WriteStatuses

func (p *Proxy) WriteStatuses() []int

WriteStatuses lists the status the server gave each note write, in order.

type Server

type Server struct {
	*httptest.Server
	// Conditional is a server that hands out sha256 and honours baseSha256.
	// Without it the server is an older one: no hash, base ignored.
	Conditional bool
	// BeforeWrite runs before each write is applied, for a test to land a save
	// from another device in between a read and a write (with Set).
	BeforeWrite func(path string)
	// contains filtered or unexported fields
}

Server holds notes by vault-relative path.

func New

func New(t testing.TB, conditional bool, notes map[string]string) *Server

New starts a server holding notes and stops it with the test.

func (*Server) Body

func (s *Server) Body(rel string) (string, bool)

Body is a note's current text and whether it exists.

func (*Server) Delete

func (s *Server) Delete(rel string)

Delete removes a note, as another device would.

func (*Server) Reads

func (s *Server) Reads() int

Reads counts the note reads served.

func (*Server) Set

func (s *Server) Set(rel, body string)

Set is a save from another device.

func (*Server) Writes

func (s *Server) Writes() []Write

Writes lists every write the server answered, in order.

type Write

type Write struct {
	Path, Body, Base string
	// SentBase says the request carried a baseSha256 field at all.
	SentBase bool
	Refused  bool
}

Write is one write the server answered: what was sent and whether it was refused.

Jump to

Keyboard shortcuts

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