factories

package
v0.0.0-...-6ad1837 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cage

type Cage struct {
	// TestCage is the wrapped cage.
	TestCage cage.Cage

	// RootPath should be a path to the root folder of the project where the helper function used
	// to replace the hijacked values can properly accomplish its work.
	RootPath string
}

Cage wraps a test cage.Cage and replaces the command's path and args hijacked by Encage() with values appropriate for tests.

func (*Cage) Encage

func (c *Cage) Encage(monster *exec.Cmd) (*exec.Cmd, error)

Encage fixes command's path and args hijacked by TestCage.Encage().

func (*Cage) Execute

func (c *Cage) Execute() error

Execute delegates to testCage.Encage().

type File

type File struct {
	// Name is the file name.
	Name string

	// Content is the file content.
	Content string
}

File represents an OS file.

func (*File) Clone

func (f *File) Clone() FileTreeNode

Clone clones the file.

func (*File) GetName

func (f *File) GetName() string

GetName returns Name.

func (*File) IsFolder

func (f *File) IsFolder() bool

IsFolder returns false.

func (*File) Remove

func (f *File) Remove(relativePath string) error

Remove removes the file.

func (*File) SortChildren

func (f *File) SortChildren() FileTreeNode

SortChildren only returns the file.

func (*File) Write

func (f *File) Write(relativePath string) error

Write writes the file.

type FileTreeNode

type FileTreeNode interface {
	// GetName returns the name of the node.
	GetName() string

	// IsFolder returns true if the node is a Folder.
	IsFolder() bool

	// Write writes the whole subtree rooted at the node prepending the path with the given relative
	// path.
	Write(relativePath string) error

	// Clone clones the subtree rooted at the node.
	Clone() FileTreeNode

	// SortChildren sorts the children of the node and returns the node.
	SortChildren() FileTreeNode

	// Remove removes the path obtained by prepending the node name with the given relative path.
	Remove(relativePath string) error
}

FileTreeNode represents a node of the OS file tree.

func ReadFileTree

func ReadFileTree(relativePath string, readFileContents bool) (FileTreeNode, error)

ReadFileTree reads a file tree rooted at the given relative path.

func SortFileTree

func SortFileTree(subroot FileTreeNode) FileTreeNode

SortFileTree sorts a whole file subtree and returns it.

type Folder

type Folder struct {
	// Name is the folder name.
	Name string

	// Children are the files and fod
	Children []FileTreeNode
}

Folder represents an OS folder.

func (*Folder) Clone

func (f *Folder) Clone() FileTreeNode

Clone clones the subtree rooted at the folder.

func (*Folder) GetName

func (f *Folder) GetName() string

GetName returns Name.

func (*Folder) IsFolder

func (f *Folder) IsFolder() bool

IsFolder returns true.

func (*Folder) Remove

func (f *Folder) Remove(relativePath string) error

Remove removes the folder.

func (*Folder) SortChildren

func (f *Folder) SortChildren() FileTreeNode

SortChildren sorts the children of the folder and returns the folder.

func (*Folder) Write

func (f *Folder) Write(relativePath string) error

Write writes the folder.

type HTTPServerFactory

type HTTPServerFactory struct {
}

HTTPServerFactory represents a factory of HTTP servers for testing.

func (*HTTPServerFactory) NewDummy

func (f *HTTPServerFactory) NewDummy() (net.Listener, *http.Server, error)

NewDummy creates a new TCP net.Listener at a random port, a new http.ServerMux responding "PAYLOAD" at GET /dummy and a new http.Server with the new mux. This function also creates a go routine that calls server.Serve(listener).

func (*HTTPServerFactory) NewDummyUploader

func (f *HTTPServerFactory) NewDummyUploader() (net.Listener, *http.Server, error)

NewDummyUploader creates a new TCP net.Listener at a random port, a new http.ServerMux responding upload routes and a new http.Server with the new mux. This function also creates a go routine that calls server.Serve(listener).

func (*HTTPServerFactory) NewFileServer

func (f *HTTPServerFactory) NewFileServer(rootRelativePath string) (net.Listener, *http.Server, error)

NewFileServer returns a server that serves files.

type ProblemBundleFactory

type ProblemBundleFactory struct {
}

ProblemBundleFactory creates problem bundles for tests.

func (*ProblemBundleFactory) Create

func (*ProblemBundleFactory) Create(bundle FileTreeNode, relativePath string) error

CreateCpp11HelloWorldBundle creates a hello world problem bundle for tests.

type ProgramFactory

type ProgramFactory struct {
}

ProgramFactory creates program source codes for tests.

func (*ProgramFactory) Create

func (*ProgramFactory) Create(program, relativePath string) error

CreateCpp11HelloWorld outputs a c++11 hello world program to the given relative path.

Jump to

Keyboard shortcuts

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