fake

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTestRepositories

func CreateTestRepositories(project string) []*scm.Repository

CreateTestRepositories creates a set of test repositories with various labels

Example

ExampleCreateTestRepositories demonstrates using the CreateTestRepositories helper

// Create a fake provider with pre-built test data
testRepos := CreateTestRepositories("test-project")
fake := NewFake("test-project", testRepos)

// Get repositories by label
activeRepos := fake.GetRepositoriesByLabel("active")
println("Found", len(activeRepos), "active repositories")

// Get all available labels
labels := fake.GetAllLabels()
println("Available labels:", len(labels))

func New

func New(_ context.Context, project string) scm.Provider

New creates a new fake SCM provider with the specified project

Types

type Fake

type Fake struct {
	Project      string
	Repositories []*scm.Repository
	PullRequests map[string]*scm.PullRequest // key: "repo:branch"
	Errors       map[string]error            // configurable errors for testing
	Capabilities *scm.Capabilities           // configurable capabilities for testing
}

Fake implements a mock SCM provider for testing purposes

Example (BasicUsage)

ExampleFake_basicUsage demonstrates basic usage of the fake SCM provider

ctx := context.Background()
// Create a new fake provider
fake := New(ctx, "my-project").(*Fake)

// Add some test repositories
fake.AddRepository(&scm.Repository{
	Name:        "repo-1",
	Description: "First repository",
	Project:     "my-project",
	Labels:      []string{"backend", "go"},
})

fake.AddRepository(&scm.Repository{
	Name:        "repo-2",
	Description: "Second repository",
	Project:     "my-project",
	Labels:      []string{"frontend", "javascript"},
})

// List repositories
repos, _ := fake.ListRepositories()
println("Found", len(repos), "repositories")

// Create a pull request
pr, _ := fake.OpenPullRequest("repo-1", "feature-branch", &scm.PROptions{Title: "My Feature", Description: "Description", Reviewers: []string{"reviewer1"}})
println("Created PR with ID:", pr.ID)
Example (ErrorTesting)

ExampleFake_errorTesting demonstrates how to configure errors for testing

ctx := context.Background()
fake := New(ctx, "test-project").(*Fake)

// Configure the provider to return an error
fake.SetError("ListRepositories", fmt.Errorf("simulated API error"))

// Now ListRepositories will return the configured error
_, err := fake.ListRepositories()
if err != nil {
	println("Got expected error:", err.Error())
}

// Clear the error
fake.ClearError("ListRepositories")

// Now it works normally again
repos, err := fake.ListRepositories()
if err == nil {
	println("No error, found", len(repos), "repositories")
}

func NewFake

func NewFake(project string, repos []*scm.Repository, caps ...*scm.Capabilities) *Fake

NewFake creates a new fake SCM provider with the specified project and optional seed data. Optionally pass a Capabilities struct to override the default (which supports all features).

func (*Fake) AddRepositories

func (f *Fake) AddRepositories(repos ...*scm.Repository)

AddRepositories adds multiple repositories to the fake provider

func (*Fake) AddRepository

func (f *Fake) AddRepository(repo *scm.Repository)

AddRepository adds a repository to the fake provider

func (*Fake) CheckCapabilities added in v0.11.0

func (f *Fake) CheckCapabilities(opts *scm.PROptions) error

CheckCapabilities validates that the provided PR options are supported by the fake provider.

func (*Fake) Clear

func (f *Fake) Clear()

Clear removes all repositories and pull requests

func (*Fake) ClearAllErrors

func (f *Fake) ClearAllErrors()

ClearAllErrors removes all configured errors

func (*Fake) ClearError

func (f *Fake) ClearError(method string)

ClearError removes a configured error for a specific method

func (*Fake) GetAllLabels

func (f *Fake) GetAllLabels() []string

GetAllLabels returns all unique labels across all repositories

func (*Fake) GetPullRequest

func (f *Fake) GetPullRequest(repo, branch string) (*scm.PullRequest, error)

GetPullRequest retrieves a pull request by repository name and source branch

func (*Fake) GetPullRequestCount

func (f *Fake) GetPullRequestCount() int

GetPullRequestCount returns the number of pull requests in the fake provider

func (*Fake) GetRepositoriesByLabel

func (f *Fake) GetRepositoriesByLabel(label string) []*scm.Repository

GetRepositoriesByLabel returns repositories that have the specified label

func (*Fake) GetRepositoryByName

func (f *Fake) GetRepositoryByName(name string) *scm.Repository

GetRepositoryByName returns a repository by name, or nil if not found

func (*Fake) GetRepositoryCount

func (f *Fake) GetRepositoryCount() int

GetRepositoryCount returns the number of repositories in the fake provider

func (*Fake) HasPullRequest

func (f *Fake) HasPullRequest(repo, branch string) bool

HasPullRequest checks if a pull request exists for the given repo and branch

func (*Fake) ListRepositories

func (f *Fake) ListRepositories() ([]*scm.Repository, error)

ListRepositories returns the configured repositories

func (*Fake) MergePullRequest

func (f *Fake) MergePullRequest(repo, branch string, opts *scm.PRMergeOptions) (*scm.PullRequest, error)

MergePullRequest merges an existing pull request

func (*Fake) OpenPullRequest

func (f *Fake) OpenPullRequest(repo, branch string, opts *scm.PROptions) (*scm.PullRequest, error)

OpenPullRequest creates a new pull request

func (*Fake) SeedErrors

func (f *Fake) SeedErrors(errors map[string]error)

SeedErrors configures the provider to return specific errors for testing

func (*Fake) SetError

func (f *Fake) SetError(method string, err error)

SetError configures the provider to return an error for a specific method

func (*Fake) SetPRMergeable added in v0.9.6

func (f *Fake) SetPRMergeable(repo, branch string, mergeable bool) error

SetPRMergeable sets the mergeable status of a pull request for testing

func (*Fake) UpdatePullRequest

func (f *Fake) UpdatePullRequest(repo, branch string, opts *scm.PROptions) (*scm.PullRequest, error)

UpdatePullRequest updates an existing pull request

Jump to

Keyboard shortcuts

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