p9test

package
v0.0.0-...-8516598 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package p9test provides standard mocks for p9.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakePath

func MakePath() uint64

MakePath returns a globally unique path.

Types

type Generator

type Generator func(parent *Mock) *Mock

Generator is a function that generates a new file.

type Harness

type Harness struct {
	Attacher *MockAttacher
	// contains filtered or unexported fields
}

Harness is an attacher mock.

func NewHarness

func NewHarness(t *testing.T) (*Harness, *p9.Client)

NewHarness creates and returns a new test server.

It should always be used as:

h, c := NewHarness(t)
defer h.Finish()

func (*Harness) Finish

func (h *Harness) Finish()

Finish completes all checks and shuts down the server.

func (*Harness) NewBlockDevice

func (h *Harness) NewBlockDevice() Generator

NewBlockDevice returns a new mock block device.

func (*Harness) NewCharacterDevice

func (h *Harness) NewCharacterDevice() Generator

NewCharacterDevice returns a new mock character device.

func (*Harness) NewDirectory

func (h *Harness) NewDirectory(contents map[string]Generator) Generator

NewDirectory returns a new mock directory.

Note that Mkdir, Link, Mknod, RenameAt, UnlinkAt and Readdir must be mocked separately. Walk is provided and children may be manipulated via AddChild and RemoveChild. After calling Walk remotely, one can use Pop to find the corresponding backend mock on the server side.

func (*Harness) NewFile

func (h *Harness) NewFile() Generator

NewFile returns a new file mock.

Note that ReadAt and WriteAt must be mocked separately.

func (*Harness) NewMock

func (h *Harness) NewMock(parent *Mock, path uint64, attr p9.Attr) *Mock

NewMock returns a new base file.

func (*Harness) NewNamedPipe

func (h *Harness) NewNamedPipe() Generator

NewNamedPipe returns a new mock named pipe.

func (*Harness) NewSocket

func (h *Harness) NewSocket() Generator

NewSocket returns a new mock socket.

func (h *Harness) NewSymlink() Generator

NewSymlink returns a new mock directory.

Note that Readlink must be mocked separately.

func (*Harness) Pop

func (h *Harness) Pop(clientFile p9.File) *Mock

Pop pops off the most recently created Mock and assert that this mock represents the same file passed in. If nil is passed in, no check is performed.

Precondition: there must be at least one Mock or this will panic.

type Mock

type Mock struct {
	p9.DefaultWalkGetAttr
	*MockFile

	QID  p9.QID
	Attr p9.Attr

	// WalkCallback is a special function that will be called from within
	// the walk context. This is needed for the concurrent tests within
	// this package.
	WalkCallback func() error
	// contains filtered or unexported fields
}

Mock is a common mock element.

func (*Mock) AddChild

func (m *Mock) AddChild(name string, generator Generator)

AddChild adds a new child to the Mock.

func (*Mock) GetAttr

func (m *Mock) GetAttr(mask p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error)

GetAttr returns the current attributes.

func (*Mock) Matches

func (m *Mock) Matches(x any) bool

Matches implements gomock.Matcher.Matches.

func (*Mock) RemoveChild

func (m *Mock) RemoveChild(name string)

RemoveChild removes the child with the given name.

func (*Mock) String

func (m *Mock) String() string

String implements gomock.Matcher.String.

func (*Mock) Walk

func (m *Mock) Walk(names []string) ([]p9.QID, p9.File, error)

Walk supports clone and walking in directories.

func (*Mock) WalkGetAttr

func (m *Mock) WalkGetAttr(names []string) ([]p9.QID, p9.File, p9.AttrMask, p9.Attr, error)

WalkGetAttr calls the default implementation; this is a client-side optimization.

Jump to

Keyboard shortcuts

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