gocmd

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gocmd provides Go command. For example, 'go get', 'go build', 'go mod'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// Get executes 'go get' with args.
	Get(ctx context.Context, args ...string) error
	// Build executes 'go build' with args.
	Build(ctx context.Context, args ...string) error
	// ModTidy executes 'go mod tidy'.
	ModTidy(ctx context.Context) error
	// ModDownload executes 'go mod download'
	ModDownload(ctx context.Context) error
	// List executes 'go list' with args.
	// The result is represents as an io.Reader.
	List(ctx context.Context, args ...string) (io.Reader, error)
	// Env executes 'go env' with args
	// The resutl is represents as an io.Reder.
	Env(ctx context.Context, args ...string) (io.Reader, error)
}

Command provides available Go commands. Each comamnd may return these errors:

  • *TimeoutErr: comamnd timed out
  • context.Canceled: context is canceled
  • others: command execution error

func New

func New() Command

New returns a new instance of Command.

type CommandMock

type CommandMock struct {
	// BuildFunc mocks the Build method.
	BuildFunc func(ctx context.Context, args ...string) error

	// EnvFunc mocks the Env method.
	EnvFunc func(ctx context.Context, args ...string) (io.Reader, error)

	// GetFunc mocks the Get method.
	GetFunc func(ctx context.Context, args ...string) error

	// ListFunc mocks the List method.
	ListFunc func(ctx context.Context, args ...string) (io.Reader, error)

	// ModDownloadFunc mocks the ModDownload method.
	ModDownloadFunc func(ctx context.Context) error

	// ModTidyFunc mocks the ModTidy method.
	ModTidyFunc func(ctx context.Context) error
	// contains filtered or unexported fields
}

CommandMock is a mock implementation of Command.

    func TestSomethingThatUsesCommand(t *testing.T) {

        // make and configure a mocked Command
        mockedCommand := &CommandMock{
            BuildFunc: func(ctx context.Context, args ...string) error {
	               panic("mock out the Build method")
            },
            EnvFunc: func(ctx context.Context, args ...string) (io.Reader, error) {
	               panic("mock out the Env method")
            },
            GetFunc: func(ctx context.Context, args ...string) error {
	               panic("mock out the Get method")
            },
            ListFunc: func(ctx context.Context, args ...string) (io.Reader, error) {
	               panic("mock out the List method")
            },
            ModDownloadFunc: func(ctx context.Context) error {
	               panic("mock out the ModDownload method")
            },
            ModTidyFunc: func(ctx context.Context) error {
	               panic("mock out the ModTidy method")
            },
        }

        // use mockedCommand in code that requires Command
        // and then make assertions.

    }

func (*CommandMock) Build

func (mock *CommandMock) Build(ctx context.Context, args ...string) error

Build calls BuildFunc.

func (*CommandMock) BuildCalls

func (mock *CommandMock) BuildCalls() []struct {
	Ctx  context.Context
	Args []string
}

BuildCalls gets all the calls that were made to Build. Check the length with:

len(mockedCommand.BuildCalls())

func (*CommandMock) Env added in v0.1.1

func (mock *CommandMock) Env(ctx context.Context, args ...string) (io.Reader, error)

Env calls EnvFunc.

func (*CommandMock) EnvCalls added in v0.1.1

func (mock *CommandMock) EnvCalls() []struct {
	Ctx  context.Context
	Args []string
}

EnvCalls gets all the calls that were made to Env. Check the length with:

len(mockedCommand.EnvCalls())

func (*CommandMock) Get

func (mock *CommandMock) Get(ctx context.Context, args ...string) error

Get calls GetFunc.

func (*CommandMock) GetCalls

func (mock *CommandMock) GetCalls() []struct {
	Ctx  context.Context
	Args []string
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedCommand.GetCalls())

func (*CommandMock) List

func (mock *CommandMock) List(ctx context.Context, args ...string) (io.Reader, error)

List calls ListFunc.

func (*CommandMock) ListCalls

func (mock *CommandMock) ListCalls() []struct {
	Ctx  context.Context
	Args []string
}

ListCalls gets all the calls that were made to List. Check the length with:

len(mockedCommand.ListCalls())

func (*CommandMock) ModDownload

func (mock *CommandMock) ModDownload(ctx context.Context) error

ModDownload calls ModDownloadFunc.

func (*CommandMock) ModDownloadCalls

func (mock *CommandMock) ModDownloadCalls() []struct {
	Ctx context.Context
}

ModDownloadCalls gets all the calls that were made to ModDownload. Check the length with:

len(mockedCommand.ModDownloadCalls())

func (*CommandMock) ModTidy

func (mock *CommandMock) ModTidy(ctx context.Context) error

ModTidy calls ModTidyFunc.

func (*CommandMock) ModTidyCalls

func (mock *CommandMock) ModTidyCalls() []struct {
	Ctx context.Context
}

ModTidyCalls gets all the calls that were made to ModTidy. Check the length with:

len(mockedCommand.ModTidyCalls())

type TimeoutErr

type TimeoutErr struct {
	Command string
}

func (*TimeoutErr) Error

func (e *TimeoutErr) Error() string

Jump to

Keyboard shortcuts

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