mock

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mock provides simulated database and bucket functions for unit testing.

Index

Constants

View Source
const (
	PrivateFile fs.FileMode = 0o600                 // PrivateFile mode means only the owner has read/write access.
	PrivateDir  fs.FileMode = 0o700                 // PrivateDir mode means only the owner has read/write/dir access.
	SevenZip                = "test/randomfiles.7z" //
	NoSuchFile              = "qwertryuiop"         // NoSuchFile is a non-existent filename.

)

Variables

View Source
var (
	ErrBucket    = errors.New("mock bucket number does not exist")
	ErrExport    = errors.New("mock export number does not exist")
	ErrExtension = errors.New("mock file for extension does not exist")
	ErrItem      = errors.New("mock item number does not exist")
	ErrLockedDB  = errors.New("mock database is locked by the Windows filesystem")
	ErrNoRoot    = errors.New("could not determine the root directory")
)
View Source
var ErrRuntime = errors.New("runtime caller failed")

Functions

func Bucket added in v1.1.0

func Bucket(t *testing.T, i int) (string, error)

Bucket returns the absolute path of test bucket.

func CSV added in v1.1.0

func CSV(t *testing.T) string

CSV returns the path to a mock exported comma-separated values file.

func Create added in v1.1.0

func Create(t *testing.T) string

Create the mock database and return its location. Note: If this test fails under Windows, try running `go test ./...` after closing VS Code. https://github.com/electron-userland/electron-builder/issues/3666

func Database added in v1.1.0

func Database(t *testing.T) (*bolt.DB, string)

Database creates, opens and returns the mock database.

func Export added in v1.1.0

func Export(t *testing.T, i int) string

Export returns the absolute path of export csv file for a bucket.

func Extension added in v1.1.0

func Extension(t *testing.T, ext string) string

Extension returns the absolute path of a test file based on an extension.

func Item added in v1.1.0

func Item(t *testing.T, i int) string

Item returns the absolute path of test source file item.

func ItemSum added in v1.1.0

func ItemSum(t *testing.T, item int) string

ItemSum returns the SHA-256 binary checksum of the test source file item.

func MirrorData added in v1.2.0

func MirrorData(t *testing.T) string

MirrorData recursively copies the directory content of src into the hidden tmp mock directory.

func NamedDB added in v1.1.0

func NamedDB(t *testing.T) string

NamedDB returns the absolute path of a mock Bolt database with a randomly generated filename.

func Open

func Open(t *testing.T, path string) (*bolt.DB, string)

Open the mock database. This will need to be closed after use.

func RemoveTmp added in v1.1.0

func RemoveTmp(t *testing.T, path string) int

RemoveTmp deletes the hidden tmp mock directory and returns the number of files deleted.

func RootDir

func RootDir(t *testing.T) string

RootDir returns the root directory of the program's source code.

func SensenTmp added in v1.1.0

func SensenTmp(t *testing.T, path string) int64

SensenTmp generates 25 subdirectories within a hidden tmp mock directory, and copies a mock Windows/DOS .exe program file into one. The returned int is the number of bytes copied.

func Sum added in v1.1.0

func Sum(t *testing.T, item int, b [32]byte) bool

Sum compares b against the expected SHA-256 binary checksum of the test source file item.

func TempDir added in v1.1.0

func TempDir(t *testing.T) string

TempDir returns a hidden tmp mock directory path within the root directory of the program's source code. If the directory doesn't exist, it is created.

Types

This section is empty.

Jump to

Keyboard shortcuts

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