testutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides utilities for reading testdata from children directories.

Index

Constants

This section is empty.

Variables

View Source
var FakeComponentData = `` /* 162-byte string literal not displayed */

FakeComponentData is simple fake component data string that should always parse.

Functions

func ReadData added in v0.5.0

func ReadData(pathToRoot, file string) ([]byte, error)

ReadData reads the test-data from disk.

func TestPathPrefix

func TestPathPrefix(pathToRoot, file string) string

TestPathPrefix returns the empty string or the bazel test path prefix.

Types

type FakeReaderWriter

type FakeReaderWriter struct {
	PathToFiles map[string]string
}

FakeReaderWriter is a fake implementation of FileReaderWriter for unit tests. If a path is not in the PathToFiles, both reads and writes will fail.

func NewEmptyReaderWriter

func NewEmptyReaderWriter() *FakeReaderWriter

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

func NewFakeReaderWriter

func NewFakeReaderWriter(files map[string]string) *FakeReaderWriter

NewFakeReaderWriter returns a FakeReaderWriter that will fake a successful read/write when the given validFile is passed into the ReadBundleFile or WriteBundleFile functions.

func NewFakeReaderWriterFromPairs

func NewFakeReaderWriterFromPairs(pairs ...*FilePair) *FakeReaderWriter

NewFakeReaderWriterFromPairs creates a map based on pairs of string inputs

func (*FakeReaderWriter) ReadFile

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

ReadFile reads a file from the map

func (*FakeReaderWriter) ReadFileObj added in v0.5.0

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

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

func (*FakeReaderWriter) WriteFile

func (f *FakeReaderWriter) WriteFile(_ context.Context, path string, bytes []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

Jump to

Keyboard shortcuts

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