clitest

package
v0.1.15824 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package clitest contains common utilities and helpers for testing the CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldFail added in v0.1.7868

func ShouldFail() types.GomegaMatcher

On Unix, we want to assert that processed exited with 255 On Windows, it should be -1.

func WithCapturedOutput

func WithCapturedOutput(f func()) string

WithCapturedOutput will call the provided function and capture any output to stdout which is returned as a string.

Types

type MockRequestResponse

type MockRequestResponse struct {
	Request       string
	Status        int
	Response      string
	ErrorResponse string
}

MockRequestResponse is a helpful type for mocking HTTP handlers.

type TempSettings

type TempSettings struct {
	Home       string
	TestServer *ghttp.Server
	Config     *TmpFile
	Update     *TmpFile
}

TempSettings contains useful settings for testing the CLI

func WithTempSettings

func WithTempSettings() *TempSettings

WithTempSettings should be called in a BeforeEach and returns a new TempSettings with everything setup for you

func (*TempSettings) AppendPostHandler

func (tempSettings *TempSettings) AppendPostHandler(authToken string, combineHandlers ...MockRequestResponse)

AppendPostHandler stubs out the provided MockRequestResponse. When authToken is an empty string no token validation is performed.

func (TempSettings) AssertConfigRereadMatches

func (tempSettings TempSettings) AssertConfigRereadMatches(contents string)

AssertConfigRereadMatches re-opens the config file and checks it's contents against the given string

func (*TempSettings) Close added in v0.1.7868

func (settings *TempSettings) Close() error

Close should be called in an AfterEach and cleans up the temp directory and server process

func (*TempSettings) NewFakeClient

func (tempSettings *TempSettings) NewFakeClient(endpoint, token string) *graphql.Client

NewFakeClient returns a new *client.Client with the TestServer set and the provided endpoint, token.

type TmpFile

type TmpFile struct {
	RootDir string
	Path    string
	File    *os.File
}

TmpFile wraps a temporary file on disk for utility.

func OpenTmpFile

func OpenTmpFile(directory string, path string) *TmpFile

OpenTmpFile will create a new temporary file in the provided directory with a name of the given path.

func (*TmpFile) Close added in v0.1.7868

func (tempFile *TmpFile) Close() error

func (TmpFile) Write

func (f TmpFile) Write(contents []byte)

Write will write the given contents to the file on disk and close it.

Jump to

Keyboard shortcuts

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