mocks

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestProjectManager

func NewTestProjectManager(t *testing.T, gitFactory project.GitManagerFactory) project.ProjectManager

NewTestProjectManager creates a real ProjectManager backed by a file-isolated config via testenv. Use this for tests that need actual registry persistence (Register, Remove, List round-trips). Pass a GitManagerFactory to enable worktree operations, or nil for registry-only tests.

Types

type ProjectManagerMock

type ProjectManagerMock struct {
	// CurrentProjectFunc mocks the CurrentProject method.
	CurrentProjectFunc func(ctx context.Context) (project.Project, error)

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

	// ListFunc mocks the List method.
	ListFunc func(ctx context.Context) ([]config.ProjectEntry, error)

	// ListWorktreesFunc mocks the ListWorktrees method.
	ListWorktreesFunc func(ctx context.Context) ([]project.WorktreeState, error)

	// RegisterFunc mocks the Register method.
	RegisterFunc func(ctx context.Context, name string, repoPath string) (project.Project, error)

	// RemoveFunc mocks the Remove method.
	RemoveFunc func(ctx context.Context, root string) error

	// ResolvePathFunc mocks the ResolvePath method.
	ResolvePathFunc func(ctx context.Context, cwd string) (project.Project, error)

	// UpdateFunc mocks the Update method.
	UpdateFunc func(ctx context.Context, entry config.ProjectEntry) (project.Project, error)
	// contains filtered or unexported fields
}

ProjectManagerMock is a mock implementation of project.ProjectManager.

func TestSomethingThatUsesProjectManager(t *testing.T) {

	// make and configure a mocked project.ProjectManager
	mockedProjectManager := &ProjectManagerMock{
		CurrentProjectFunc: func(ctx context.Context) (project.Project, error) {
			panic("mock out the CurrentProject method")
		},
		GetFunc: func(ctx context.Context, root string) (project.Project, error) {
			panic("mock out the Get method")
		},
		ListFunc: func(ctx context.Context) ([]config.ProjectEntry, error) {
			panic("mock out the List method")
		},
		ListWorktreesFunc: func(ctx context.Context) ([]project.WorktreeState, error) {
			panic("mock out the ListWorktrees method")
		},
		RegisterFunc: func(ctx context.Context, name string, repoPath string) (project.Project, error) {
			panic("mock out the Register method")
		},
		RemoveFunc: func(ctx context.Context, root string) error {
			panic("mock out the Remove method")
		},
		ResolvePathFunc: func(ctx context.Context, cwd string) (project.Project, error) {
			panic("mock out the ResolvePath method")
		},
		UpdateFunc: func(ctx context.Context, entry config.ProjectEntry) (project.Project, error) {
			panic("mock out the Update method")
		},
	}

	// use mockedProjectManager in code that requires project.ProjectManager
	// and then make assertions.

}

func NewMockProjectManager

func NewMockProjectManager() *ProjectManagerMock

NewMockProjectManager returns a ProjectManagerMock with safe no-op defaults. All methods return zero values instead of panicking via moq's nil-func guard. Tests override only the methods they care about.

func (*ProjectManagerMock) CurrentProject

func (mock *ProjectManagerMock) CurrentProject(ctx context.Context) (project.Project, error)

CurrentProject calls CurrentProjectFunc.

func (*ProjectManagerMock) CurrentProjectCalls

func (mock *ProjectManagerMock) CurrentProjectCalls() []struct {
	Ctx context.Context
}

CurrentProjectCalls gets all the calls that were made to CurrentProject. Check the length with:

len(mockedProjectManager.CurrentProjectCalls())

func (*ProjectManagerMock) Get

func (mock *ProjectManagerMock) Get(ctx context.Context, root string) (project.Project, error)

Get calls GetFunc.

func (*ProjectManagerMock) GetCalls

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

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

len(mockedProjectManager.GetCalls())

func (*ProjectManagerMock) List

List calls ListFunc.

func (*ProjectManagerMock) ListCalls

func (mock *ProjectManagerMock) ListCalls() []struct {
	Ctx context.Context
}

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

len(mockedProjectManager.ListCalls())

func (*ProjectManagerMock) ListWorktrees

func (mock *ProjectManagerMock) ListWorktrees(ctx context.Context) ([]project.WorktreeState, error)

ListWorktrees calls ListWorktreesFunc.

func (*ProjectManagerMock) ListWorktreesCalls

func (mock *ProjectManagerMock) ListWorktreesCalls() []struct {
	Ctx context.Context
}

ListWorktreesCalls gets all the calls that were made to ListWorktrees. Check the length with:

len(mockedProjectManager.ListWorktreesCalls())

func (*ProjectManagerMock) Register

func (mock *ProjectManagerMock) Register(ctx context.Context, name string, repoPath string) (project.Project, error)

Register calls RegisterFunc.

func (*ProjectManagerMock) RegisterCalls

func (mock *ProjectManagerMock) RegisterCalls() []struct {
	Ctx      context.Context
	Name     string
	RepoPath string
}

RegisterCalls gets all the calls that were made to Register. Check the length with:

len(mockedProjectManager.RegisterCalls())

func (*ProjectManagerMock) Remove

func (mock *ProjectManagerMock) Remove(ctx context.Context, root string) error

Remove calls RemoveFunc.

func (*ProjectManagerMock) RemoveCalls

func (mock *ProjectManagerMock) RemoveCalls() []struct {
	Ctx  context.Context
	Root string
}

RemoveCalls gets all the calls that were made to Remove. Check the length with:

len(mockedProjectManager.RemoveCalls())

func (*ProjectManagerMock) ResolvePath

func (mock *ProjectManagerMock) ResolvePath(ctx context.Context, cwd string) (project.Project, error)

ResolvePath calls ResolvePathFunc.

func (*ProjectManagerMock) ResolvePathCalls

func (mock *ProjectManagerMock) ResolvePathCalls() []struct {
	Ctx context.Context
	Cwd string
}

ResolvePathCalls gets all the calls that were made to ResolvePath. Check the length with:

len(mockedProjectManager.ResolvePathCalls())

func (*ProjectManagerMock) Update

Update calls UpdateFunc.

func (*ProjectManagerMock) UpdateCalls

func (mock *ProjectManagerMock) UpdateCalls() []struct {
	Ctx   context.Context
	Entry config.ProjectEntry
}

UpdateCalls gets all the calls that were made to Update. Check the length with:

len(mockedProjectManager.UpdateCalls())

type ProjectMock

type ProjectMock struct {
	// AddWorktreeFunc mocks the AddWorktree method.
	AddWorktreeFunc func(ctx context.Context, branch string, base string) (project.WorktreeState, error)

	// CreateWorktreeFunc mocks the CreateWorktree method.
	CreateWorktreeFunc func(ctx context.Context, branch string, base string) (string, error)

	// GetWorktreeFunc mocks the GetWorktree method.
	GetWorktreeFunc func(ctx context.Context, branch string) (project.WorktreeState, error)

	// ListWorktreesFunc mocks the ListWorktrees method.
	ListWorktreesFunc func(ctx context.Context) ([]project.WorktreeState, error)

	// NameFunc mocks the Name method.
	NameFunc func() string

	// PruneStaleWorktreesFunc mocks the PruneStaleWorktrees method.
	PruneStaleWorktreesFunc func(ctx context.Context, dryRun bool) (*project.PruneStaleResult, error)

	// RecordFunc mocks the Record method.
	RecordFunc func() (project.ProjectRecord, error)

	// RemoveWorktreeFunc mocks the RemoveWorktree method.
	RemoveWorktreeFunc func(ctx context.Context, branch string, deleteBranch bool) error

	// RepoPathFunc mocks the RepoPath method.
	RepoPathFunc func() string
	// contains filtered or unexported fields
}

ProjectMock is a mock implementation of project.Project.

func TestSomethingThatUsesProject(t *testing.T) {

	// make and configure a mocked project.Project
	mockedProject := &ProjectMock{
		AddWorktreeFunc: func(ctx context.Context, branch string, base string) (project.WorktreeState, error) {
			panic("mock out the AddWorktree method")
		},
		CreateWorktreeFunc: func(ctx context.Context, branch string, base string) (string, error) {
			panic("mock out the CreateWorktree method")
		},
		GetWorktreeFunc: func(ctx context.Context, branch string) (project.WorktreeState, error) {
			panic("mock out the GetWorktree method")
		},
		ListWorktreesFunc: func(ctx context.Context) ([]project.WorktreeState, error) {
			panic("mock out the ListWorktrees method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		PruneStaleWorktreesFunc: func(ctx context.Context, dryRun bool) (*project.PruneStaleResult, error) {
			panic("mock out the PruneStaleWorktrees method")
		},
		RecordFunc: func() (project.ProjectRecord, error) {
			panic("mock out the Record method")
		},
		RemoveWorktreeFunc: func(ctx context.Context, branch string, deleteBranch bool) error {
			panic("mock out the RemoveWorktree method")
		},
		RepoPathFunc: func() string {
			panic("mock out the RepoPath method")
		},
	}

	// use mockedProject in code that requires project.Project
	// and then make assertions.

}

func NewMockProject

func NewMockProject(name, repoPath string) *ProjectMock

NewMockProject returns a ProjectMock with the given name and repoPath wired. Read accessors (Name, RepoPath, Record) are populated; mutation methods (CreateWorktree, RemoveWorktree, etc.) return zero values.

func (*ProjectMock) AddWorktree

func (mock *ProjectMock) AddWorktree(ctx context.Context, branch string, base string) (project.WorktreeState, error)

AddWorktree calls AddWorktreeFunc.

func (*ProjectMock) AddWorktreeCalls

func (mock *ProjectMock) AddWorktreeCalls() []struct {
	Ctx    context.Context
	Branch string
	Base   string
}

AddWorktreeCalls gets all the calls that were made to AddWorktree. Check the length with:

len(mockedProject.AddWorktreeCalls())

func (*ProjectMock) CreateWorktree

func (mock *ProjectMock) CreateWorktree(ctx context.Context, branch string, base string) (string, error)

CreateWorktree calls CreateWorktreeFunc.

func (*ProjectMock) CreateWorktreeCalls

func (mock *ProjectMock) CreateWorktreeCalls() []struct {
	Ctx    context.Context
	Branch string
	Base   string
}

CreateWorktreeCalls gets all the calls that were made to CreateWorktree. Check the length with:

len(mockedProject.CreateWorktreeCalls())

func (*ProjectMock) GetWorktree

func (mock *ProjectMock) GetWorktree(ctx context.Context, branch string) (project.WorktreeState, error)

GetWorktree calls GetWorktreeFunc.

func (*ProjectMock) GetWorktreeCalls

func (mock *ProjectMock) GetWorktreeCalls() []struct {
	Ctx    context.Context
	Branch string
}

GetWorktreeCalls gets all the calls that were made to GetWorktree. Check the length with:

len(mockedProject.GetWorktreeCalls())

func (*ProjectMock) ListWorktrees

func (mock *ProjectMock) ListWorktrees(ctx context.Context) ([]project.WorktreeState, error)

ListWorktrees calls ListWorktreesFunc.

func (*ProjectMock) ListWorktreesCalls

func (mock *ProjectMock) ListWorktreesCalls() []struct {
	Ctx context.Context
}

ListWorktreesCalls gets all the calls that were made to ListWorktrees. Check the length with:

len(mockedProject.ListWorktreesCalls())

func (*ProjectMock) Name

func (mock *ProjectMock) Name() string

Name calls NameFunc.

func (*ProjectMock) NameCalls

func (mock *ProjectMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedProject.NameCalls())

func (*ProjectMock) PruneStaleWorktrees

func (mock *ProjectMock) PruneStaleWorktrees(ctx context.Context, dryRun bool) (*project.PruneStaleResult, error)

PruneStaleWorktrees calls PruneStaleWorktreesFunc.

func (*ProjectMock) PruneStaleWorktreesCalls

func (mock *ProjectMock) PruneStaleWorktreesCalls() []struct {
	Ctx    context.Context
	DryRun bool
}

PruneStaleWorktreesCalls gets all the calls that were made to PruneStaleWorktrees. Check the length with:

len(mockedProject.PruneStaleWorktreesCalls())

func (*ProjectMock) Record

func (mock *ProjectMock) Record() (project.ProjectRecord, error)

Record calls RecordFunc.

func (*ProjectMock) RecordCalls

func (mock *ProjectMock) RecordCalls() []struct {
}

RecordCalls gets all the calls that were made to Record. Check the length with:

len(mockedProject.RecordCalls())

func (*ProjectMock) RemoveWorktree

func (mock *ProjectMock) RemoveWorktree(ctx context.Context, branch string, deleteBranch bool) error

RemoveWorktree calls RemoveWorktreeFunc.

func (*ProjectMock) RemoveWorktreeCalls

func (mock *ProjectMock) RemoveWorktreeCalls() []struct {
	Ctx          context.Context
	Branch       string
	DeleteBranch bool
}

RemoveWorktreeCalls gets all the calls that were made to RemoveWorktree. Check the length with:

len(mockedProject.RemoveWorktreeCalls())

func (*ProjectMock) RepoPath

func (mock *ProjectMock) RepoPath() string

RepoPath calls RepoPathFunc.

func (*ProjectMock) RepoPathCalls

func (mock *ProjectMock) RepoPathCalls() []struct {
}

RepoPathCalls gets all the calls that were made to RepoPath. Check the length with:

len(mockedProject.RepoPathCalls())

Jump to

Keyboard shortcuts

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