cmdtest

package
v1.81.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package cmdtest is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ProjectPath    string
	GlabBinaryPath string
)

Functions

func CopyTestRepo

func CopyTestRepo(log fatalLogger, name string) string

func InitTest

func InitTest(m *testing.M, suffix string)

func NewTestApiClient

func NewTestApiClient(t *testing.T, httpClient *http.Client, token, host string, options ...api.ClientOption) *api.Client

func NewTestOAuth2ApiClient added in v1.75.0

func NewTestOAuth2ApiClient(t *testing.T, httpClient *http.Client, tokenSource oauth2.TokenSource, host string, options ...api.ClientOption) *api.Client

func SliceMatch added in v1.81.0

func SliceMatch[T any](elements ...any) gomock.Matcher

SliceMatch returns a matcher that matches a []T slice element-by-element. Elements can be values of type T (exact match) or gomock.Matcher instances.

func WithTestIOStreamsAsTTY

func WithTestIOStreamsAsTTY(asTTY bool) iostreams.IOStreamsOption

WithTestIOStreamsAsTTY sets stdin, stdout and stderr as TTY By default they are not treated as TTYs. This will overwrite the behavior for the three of them. If you only want to set a specific one, use iostreams.WithStdin, iostreams.WithStdout or iostreams.WithStderr.

Types

type CmdExecFunc

type CmdExecFunc func(cli string) (*test.CmdOut, error)

func SetupCmdForTest

func SetupCmdForTest(t *testing.T, cmdFunc CmdFunc, isTTY bool, opts ...FactoryOption) CmdExecFunc

SetupCmdForTest creates a test environment with a configured Factory

type CmdFunc

type CmdFunc func(cmdutils.Factory) *cobra.Command

type Factory

type Factory struct {
	ApiClientStub    func(repoHost string) (*api.Client, error)
	GitLabClientStub func() (*gitlab.Client, error)
	BaseRepoStub     func() (glrepo.Interface, error)
	RemotesStub      func() (glrepo.Remotes, error)
	ConfigStub       func() config.Config
	BranchStub       func() (string, error)
	IOStub           *iostreams.IOStreams
	BuildInfoStub    api.BuildInfo
	ExecutorStub     cmdutils.Executor
	// contains filtered or unexported fields
}

func NewTestFactory

func NewTestFactory(ios *iostreams.IOStreams, opts ...FactoryOption) *Factory

NewTestFactory creates a Factory configured for testing with the given options

func (*Factory) ApiClient

func (f *Factory) ApiClient(repoHost string) (*api.Client, error)

func (*Factory) BaseRepo

func (f *Factory) BaseRepo() (glrepo.Interface, error)

func (*Factory) Branch

func (f *Factory) Branch() (string, error)

func (*Factory) BuildInfo

func (f *Factory) BuildInfo() api.BuildInfo

func (*Factory) Config

func (f *Factory) Config() config.Config

func (*Factory) DefaultHostname

func (f *Factory) DefaultHostname() string

func (*Factory) Executor added in v1.81.0

func (f *Factory) Executor() cmdutils.Executor

func (*Factory) GitLabClient added in v1.66.0

func (f *Factory) GitLabClient() (*gitlab.Client, error)

func (*Factory) IO

func (f *Factory) IO() *iostreams.IOStreams

func (*Factory) Remotes

func (f *Factory) Remotes() (glrepo.Remotes, error)

func (*Factory) RepoOverride

func (f *Factory) RepoOverride(repo string) error

type FactoryOption

type FactoryOption func(f *Factory)

FactoryOption is a function that configures a Factory

func WithApiClient

func WithApiClient(client *api.Client) FactoryOption

WithApiClient configures the Factory with a specific API client

func WithBaseRepo

func WithBaseRepo(owner, repo string, hostname string) FactoryOption

WithBaseRepo configures the Factory with a specific base repository

func WithBaseRepoError

func WithBaseRepoError(err error) FactoryOption

WithBaseRepoError configures the Factory to return an error when getting base repo

func WithBranch

func WithBranch(branch string) FactoryOption

WithBranch configures the Factory with a specific branch

func WithBranchError

func WithBranchError(err error) FactoryOption

WithBranchError configures the Factory to return an error when getting branch

func WithBuildInfo

func WithBuildInfo(buildInfo api.BuildInfo) FactoryOption

WithBuildInfo configures the Factory build information

func WithConfig

func WithConfig(cfg config.Config) FactoryOption

WithConfig configures the Factory with a specific config

func WithExecutor added in v1.81.0

func WithExecutor(exec cmdutils.Executor) FactoryOption

func WithGitLabClient

func WithGitLabClient(client *gitlab.Client) FactoryOption

WithGitLabClient configures the Factory with a specific GitLab client

func WithGitLabClientError added in v1.66.0

func WithGitLabClientError(err error) FactoryOption

WithGitLabClientError configures the Factory to return an error when creating GitLab client

func WithIOStreamsOverride added in v1.81.0

func WithIOStreamsOverride(ios *iostreams.IOStreams) FactoryOption

WithIOStreamsOverride configures an IOStreams instance for testing

Attention: only use as a last resort and prefer functions like WithStdin etc to configure the IOStreams that's already created.

func WithResponder added in v1.73.0

func WithResponder(t *testing.T, responder *huhtest.Responder) FactoryOption

func WithStdin added in v1.75.0

func WithStdin(stdin string) FactoryOption

WithStdin configures the Factory with specific stdin content

type MockExecutor added in v1.81.0

type MockExecutor struct {
	// contains filtered or unexported fields
}

MockExecutor is a mock of Executor interface.

func NewMockExecutor added in v1.81.0

func NewMockExecutor(ctrl *gomock.Controller) *MockExecutor

NewMockExecutor creates a new mock instance.

func (*MockExecutor) EXPECT added in v1.81.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockExecutor) Exec added in v1.81.0

func (m *MockExecutor) Exec(ctx context.Context, name string, args []string, env map[string]string) error

Exec mocks base method.

func (*MockExecutor) ExecWithCombinedOutput added in v1.81.0

func (m *MockExecutor) ExecWithCombinedOutput(ctx context.Context, name string, args []string, env map[string]string) ([]byte, error)

ExecWithCombinedOutput mocks base method.

func (*MockExecutor) ExecWithIO added in v1.81.0

func (m *MockExecutor) ExecWithIO(ctx context.Context, name string, args []string, env map[string]string, stdin io.Reader, stdout, stderr io.Writer) error

ExecWithIO mocks base method.

func (*MockExecutor) LookPath added in v1.81.0

func (m *MockExecutor) LookPath(file string) (string, error)

LookPath mocks base method.

type MockExecutorExecCall added in v1.81.0

type MockExecutorExecCall struct {
	*gomock.Call
}

MockExecutorExecCall wrap *gomock.Call

func (*MockExecutorExecCall) Do added in v1.81.0

Do rewrite *gomock.Call.Do

func (*MockExecutorExecCall) DoAndReturn added in v1.81.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockExecutorExecCall) Return added in v1.81.0

Return rewrite *gomock.Call.Return

type MockExecutorExecWithCombinedOutputCall added in v1.81.0

type MockExecutorExecWithCombinedOutputCall struct {
	*gomock.Call
}

MockExecutorExecWithCombinedOutputCall wrap *gomock.Call

func (*MockExecutorExecWithCombinedOutputCall) Do added in v1.81.0

Do rewrite *gomock.Call.Do

func (*MockExecutorExecWithCombinedOutputCall) DoAndReturn added in v1.81.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockExecutorExecWithCombinedOutputCall) Return added in v1.81.0

Return rewrite *gomock.Call.Return

type MockExecutorExecWithIOCall added in v1.81.0

type MockExecutorExecWithIOCall struct {
	*gomock.Call
}

MockExecutorExecWithIOCall wrap *gomock.Call

func (*MockExecutorExecWithIOCall) Do added in v1.81.0

Do rewrite *gomock.Call.Do

func (*MockExecutorExecWithIOCall) DoAndReturn added in v1.81.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockExecutorExecWithIOCall) Return added in v1.81.0

Return rewrite *gomock.Call.Return

type MockExecutorLookPathCall added in v1.81.0

type MockExecutorLookPathCall struct {
	*gomock.Call
}

MockExecutorLookPathCall wrap *gomock.Call

func (*MockExecutorLookPathCall) Do added in v1.81.0

Do rewrite *gomock.Call.Do

func (*MockExecutorLookPathCall) DoAndReturn added in v1.81.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockExecutorLookPathCall) Return added in v1.81.0

Return rewrite *gomock.Call.Return

type MockExecutorMockRecorder added in v1.81.0

type MockExecutorMockRecorder struct {
	// contains filtered or unexported fields
}

MockExecutorMockRecorder is the mock recorder for MockExecutor.

func (*MockExecutorMockRecorder) Exec added in v1.81.0

func (mr *MockExecutorMockRecorder) Exec(ctx, name, args, env any) *MockExecutorExecCall

Exec indicates an expected call of Exec.

func (*MockExecutorMockRecorder) ExecWithCombinedOutput added in v1.81.0

func (mr *MockExecutorMockRecorder) ExecWithCombinedOutput(ctx, name, args, env any) *MockExecutorExecWithCombinedOutputCall

ExecWithCombinedOutput indicates an expected call of ExecWithCombinedOutput.

func (*MockExecutorMockRecorder) ExecWithIO added in v1.81.0

func (mr *MockExecutorMockRecorder) ExecWithIO(ctx, name, args, env, stdin, stdout, stderr any) *MockExecutorExecWithIOCall

ExecWithIO indicates an expected call of ExecWithIO.

func (*MockExecutorMockRecorder) LookPath added in v1.81.0

LookPath indicates an expected call of LookPath.

Jump to

Keyboard shortcuts

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