mock

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Mock is a set of 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")
)

Functions

func Bucket added in v1.1.0

func Bucket(i int) (string, error)

Bucket returns the absolute path of test bucket.

func CSV added in v1.1.0

func CSV() string

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

func Create added in v1.1.0

func Create() (string, error)

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() (db *bolt.DB, path string, err error)

Database creates, opens and returns the mock database.

func Delete added in v1.1.0

func Delete(path string) error

Delete the mock database.

func Export added in v1.1.0

func Export(i int) (string, error)

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

func Extension added in v1.1.0

func Extension(ext string) (string, error)

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

func Item added in v1.1.0

func Item(i int) (string, error)

Item returns the absolute path of test source file item.

func ItemSum added in v1.1.0

func ItemSum(item int) (string, error)

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

func MirrorTmp added in v1.1.0

func MirrorTmp(src string) (string, error)

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

func NamedDB added in v1.1.0

func NamedDB() (string, error)

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

func Open

func Open(path string) (*bolt.DB, string, error)

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

func Read

func Read(name string) (sum [32]byte, err error)

Read the named file and return its SHA256 checksum.

func RemoveTmp added in v1.1.0

func RemoveTmp(path string) (int, error)

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

func RootDir

func RootDir() string

RootDir returns the root directory of the program's source code. An empty string is returned if the directory cannot be determined.

func SensenTmp added in v1.1.0

func SensenTmp(path string) (int64, error)

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(item int, b [32]byte) (bool, error)

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() (string, error)

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