cmdtest

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

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 ExecuteCommand

func ExecuteCommand(cmd *cobra.Command, cli string, stdout *bytes.Buffer, stderr *bytes.Buffer) (*test.CmdOut, error)

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 RunCommand

func RunCommand(cmd *cobra.Command, cli string, stds ...*bytes.Buffer) (*test.CmdOut, error)

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, 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)
	HttpClientStub 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
	// 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) HttpClient

func (f *Factory) HttpClient() (*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) 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 WithGitLabClient

func WithGitLabClient(client *gitlab.Client) FactoryOption

WithGitLabClient configures the Factory with a specific GitLab client

func WithHttpClientError

func WithHttpClientError(err error) FactoryOption

WithHttpClientError configures the Factory to return an error when creating HTTP client

Jump to

Keyboard shortcuts

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