testutil

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides utilities for reading testdata from children directories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeToBazelDir added in v0.9.1

func ChangeToBazelDir(curDir string)

ChangeToBazelDir changes the CWD to a bazel directory if necessary. pathToDir specifies the path from the root bazel-directory to the relevant directory. If changing the directory fails, the method panics.

func ChangeToBazelDirWithoutWorkspace added in v0.12.0

func ChangeToBazelDirWithoutWorkspace(curDir string)

ChangeToBazelDirWithoutWorkspace, like ChangeToBazelDir, changes the CWD to a bazel directory if necessary, but doesn't use the workspace path as part of the path building. If changing the directory fails, the method panics.

func CheckErrorCases added in v0.8.0

func CheckErrorCases(err error, expErrSubstr string) error

CheckErrorCases checks error cases for tests

Types

type FakeFileReaderWriter added in v0.11.0

type FakeFileReaderWriter struct {
	// ReadFiles contains mapping of path-to-file for files to-read. If
	// AlwaysRead is empty and the a path is supplied to read that is not in the
	// ReadFiles, an error will be returned.
	ReadFiles map[string]string

	// If AlwaysRead is present, always return the always read object.
	AlwaysRead string

	// ReadErr forces an error to occur during read.
	ReadErr error

	// WriteFiles records what files have been written
	WriteFiles map[string]string

	// WriteErr forces an error to occur during write.
	WriteErr error
}

FakeFileReaderWriter is a fake implementation of FileReaderWriter for unit tests.

func NewEmptyReaderWriter

func NewEmptyReaderWriter() *FakeFileReaderWriter

NewEmptyReaderWriter creates an empty FakeFileReaderWriter. It will return an error on all paths returned from reads and succeed on all writes.

func (*FakeFileReaderWriter) AddReadFile added in v0.11.0

func (f *FakeFileReaderWriter) AddReadFile(fp *FilePair)

AddReadFile adds a file to the ReadFiles map.

func (*FakeFileReaderWriter) ReadFile added in v0.11.0

func (f *FakeFileReaderWriter) ReadFile(_ context.Context, path string) ([]byte, error)

ReadFile reads a file from the map

func (*FakeFileReaderWriter) ReadFileObj added in v0.11.0

func (f *FakeFileReaderWriter) ReadFileObj(ctx context.Context, file bundle.File) ([]byte, error)

ReadFileObj reads a File object by deferring to the internal map.

func (*FakeFileReaderWriter) WriteFile added in v0.11.0

func (f *FakeFileReaderWriter) WriteFile(_ context.Context, path string, contents []byte, permissions os.FileMode) error

WriteFile checks write conditions based on path contents.

type FilePair

type FilePair struct {
	// Path is some fake file path
	Path string

	// Contents is some expected contents
	Contents string
}

FilePair is a helper for constructing a fake file reader

func (*FilePair) String

func (f *FilePair) String() string

Directories

Path Synopsis
Package componentsuite provides a test-suite helper for running component tests.
Package componentsuite provides a test-suite helper for running component tests.

Jump to

Keyboard shortcuts

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