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

testplugin

package
v0.44.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testplugin runs a real filex storage plugin — the HTTP/JSON protocol of internal/plugin, served over httptest — so any package that consumes a storage.Driver can be exercised against a PLUGIN-backed storage without spawning a second process.

Why this package exists

The plugin adapter was proven through the HTTP file manager only. Every other surface (sync, WebDAV, S3, SFTP, FTP, NFS, quota, thumbnails) reaches storage through the same storage.Driver interface, but each one leans on a different corner of it: sync stats and lists, WebDAV wants a directory at the root, SFTP writes with an unknown size, NFS asks for the same path twice. A plugin driver is NOT a local driver with a longer code path — it answers over a wire, its errors arrive as JSON codes, its instance can vanish under a restart. Those differences only show up when a surface is driven end to end, and a shell script that proves it once on a laptop proves nothing on the next release. Hence: a helper the tests share.

The fake here is deliberately written the way a third-party plugin author would write one — flat map, no filex internals — because if the protocol is awkward to implement it shows up here first.

Index

Constants

This section is empty.

Variables

View Source
var SeedTime = time.Date(2023, 11, 14, 22, 13, 20, 0, time.UTC)

SeedTime is the mtime every seeded file carries. Fixed, because a sync test that compares "changed since last pass" against time.Now() passes for the wrong reason on a fast machine.

Functions

func FullCaps

func FullCaps() plugin.Capabilities

FullCaps is everything the protocol offers. Tests that care about a specific capability being ABSENT should start here and switch one off, so the difference under test is the only difference.

Types

type Option

type Option func(*Plugin)

Option tunes a plugin before it starts.

func WithCaps

func WithCaps(c plugin.Capabilities) Option

WithCaps replaces the declared capabilities.

func WithName

func WithName(name string) Option

WithName sets the driver name; the registry sees "plugin:<name>".

type Plugin

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

Plugin is a running fake plugin: an httptest server speaking the protocol over an in-memory tree.

func Start

func Start(t *testing.T, opts ...Option) *Plugin

Start brings a plugin up and shuts it down with the test.

func (*Plugin) Counts

func (p *Plugin) Counts() (lists, reads, ranges, writes int)

Counts reports how many list/read/range/write calls reached the plugin. A surface that "works" by never touching the backend is a surface that is serving something else.

func (*Plugin) Data

func (p *Plugin) Data(pth string) ([]byte, bool)

Data returns what the plugin actually holds at pth. Assertions go through this rather than through the driver, so a surface that silently swallowed a write cannot pass by reading back its own cache.

func (*Plugin) Delete

func (p *Plugin) Delete(pth string)

Delete removes a path from the plugin's tree directly, bypassing the driver — the other half of "somebody else changed the bucket", and the only way to test that a sync notices a disappearance.

func (*Plugin) Down

func (p *Plugin) Down()

Down makes every instance call answer no_instance for good, which is what a plugin whose process is gone looks like from the host: the adapter can keep re-creating instances and keep being told they do not exist. Surfaces must report that as a failure — a "gone" plugin that renders as an empty folder or a 404 tells the user their files were deleted.

func (*Plugin) Driver

func (p *Plugin) Driver(t *testing.T) storage.Driver

Driver returns a storage.Driver already Init'ed against the plugin — the exact value the manager hands the rest of filex.

func (*Plugin) DriverName

func (p *Plugin) DriverName() string

DriverName is what the storage registry knows this plugin as.

func (*Plugin) DriverWithConfig

func (p *Plugin) DriverWithConfig(t *testing.T, cfg map[string]any) storage.Driver

DriverWithConfig is Driver with the config the admin would have saved.

func (*Plugin) Emit

func (p *Plugin) Emit(ev plugin.Event)

Emit pushes a watch event to whoever is subscribed.

func (*Plugin) Exists

func (p *Plugin) Exists(pth string) bool

Exists reports whether anything lives at pth.

func (*Plugin) NoInstanceCount

func (p *Plugin) NoInstanceCount() int

NoInstanceCount is how many times the plugin has answered no_instance. A restart test that never reaches a non-zero count proved nothing: the retry path it means to exercise was never entered.

func (*Plugin) Paths

func (p *Plugin) Paths() []string

Paths lists everything the plugin holds, sorted — useful in a failure message, where "not found" is far less informative than the actual tree.

func (*Plugin) Register

func (p *Plugin) Register(t *testing.T) string

Register puts the plugin's factory in the global storage registry under "plugin:<name>" and removes it again after the test, so surfaces that look a driver up by name (storage.Get) meet a plugin exactly as they would in production. Returns the driver name to put in the storage row.

func (*Plugin) Restart

func (p *Plugin) Restart()

Restart makes the plugin forget its instance ids exactly once, which is what a crashed-and-respawned plugin looks like from the host. The files survive, as they would on a real backend.

func (*Plugin) Seed

func (p *Plugin) Seed(pth, data string)

Seed writes a file directly into the plugin's tree, bypassing the driver — the "somebody else put this in the bucket" case every sync exists for.

func (*Plugin) SeedBytes

func (p *Plugin) SeedBytes(pth string, data []byte)

SeedBytes is Seed for content that is not a string (an image, say).

func (*Plugin) SeedDir

func (p *Plugin) SeedDir(pth string)

SeedDir creates an explicit empty directory.

func (*Plugin) URL

func (p *Plugin) URL() string

URL is the plugin's base address.

func (*Plugin) Up

func (p *Plugin) Up()

Up ends what Down started.

Jump to

Keyboard shortcuts

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