Documentation
¶
Overview ¶
Package testing provides utility functions for testing purposes across multiple packages.
Package testing provides utility functions for testing purposes across multiple packages.
Index ¶
- func AssertCatalogState(t *testing.T, catalog map[string]scm.Repository, ...)
- func AssertContains(t *testing.T, got any, want any, index ...int)
- func AssertEqual(t *testing.T, got, want any)
- func AssertError(t *testing.T, err error, wantErr bool)
- func AssertLabelContainsRepo(t *testing.T, labels map[string]mapset.Set[string], labelName string, ...)
- func AssertLabelExists(t *testing.T, labels map[string]mapset.Set[string], labelName string, ...)
- func AssertLength(t *testing.T, got any, want int)
- func AssertNotContains(t *testing.T, output any, unwanted []string)
- func AssertNotEmpty(t *testing.T, got string)
- func AssertOutput(t *testing.T, got, want []string, err error, wantErr bool)
- func AssertRepositoryExists(t *testing.T, catalog map[string]scm.Repository, repoKey string)
- func CreateTestRepositories(count int, project string, labelPrefix string) []*scm.Repository
- func CreateTestRepository(name, project string, labels []string) *scm.Repository
- func ExecCommand(t *testing.T, dir string, name string, args ...string)
- func FakeCmd(t *testing.T, ctx context.Context, out io.Writer) *cobra.Command
- func LoadFixture(t *testing.T, configPath string) context.Context
- func SetupDirs(t *testing.T, ctx context.Context, repos []string)
- func SetupFakeProvider(t *testing.T, _ context.Context, providerName string, project string) scm.Provider
- func SetupFakeProviderWithRepos(t *testing.T, _ context.Context, providerName string, project string, ...) scm.Provider
- func SetupMultipleFakeProviders(t *testing.T, _ context.Context, projects []string) map[string]scm.Provider
- func SetupRealProvider(t *testing.T, ctx context.Context, providerName string)
- func SetupRepos(t *testing.T, repos []string, branches ...bool) string
- type MockChannel
- func (m *MockChannel) Close() error
- func (m *MockChannel) Err() <-chan error
- func (m *MockChannel) Error() error
- func (m *MockChannel) Name() string
- func (m *MockChannel) Out() <-chan []byte
- func (m *MockChannel) Output() []byte
- func (m *MockChannel) Start(_ int64) error
- func (m *MockChannel) Write(p []byte) (int, error)
- func (m *MockChannel) WriteError(err error)
- func (m *MockChannel) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCatalogState ¶
func AssertCatalogState(t *testing.T, catalog map[string]scm.Repository, labels map[string]mapset.Set[string], expectedRepos int, minLabels int)
AssertCatalogState validates the state of the catalog
func AssertContains ¶
AssertContains verifies that got contains all values in want. Supports multiple type combinations: - got: string, want: string - checks substring containment - got: []string, want: string - checks if any element contains substring - got: string, want: []string - checks if string contains all substrings - got: []string, want: []string - checks if any element contains each substring - got: string/[]string, want: map[string]string - checks containment of all map values
func AssertEqual ¶
AssertEqual verifies two values are equal.
func AssertError ¶
AssertError validates that an error matches expected results.
func AssertLabelContainsRepo ¶
func AssertLabelContainsRepo(t *testing.T, labels map[string]mapset.Set[string], labelName string, repoKey string)
AssertLabelContainsRepo checks if a label contains a specific repository
func AssertLabelExists ¶
func AssertLabelExists(t *testing.T, labels map[string]mapset.Set[string], labelName string, expectedCount int)
AssertLabelExists checks if a label exists and optionally validates repository count
func AssertLength ¶
AssertLength verifies the length of a string, slice, or map using reflection.
func AssertNotContains ¶
AssertNotContains verifies a string or slice does not contain unwanted substrings. For slices, checks that no element contains any of the unwanted substrings.
func AssertNotEmpty ¶
AssertNotEmpty verifies a string is not empty.
func AssertOutput ¶
AssertOutput validates test output and error against expected values.
func AssertRepositoryExists ¶
AssertRepositoryExists checks if a repository exists in the catalog
func CreateTestRepositories ¶
func CreateTestRepositories(count int, project string, labelPrefix string) []*scm.Repository
CreateTestRepositories creates multiple test repositories
func CreateTestRepository ¶
func CreateTestRepository(name, project string, labels []string) *scm.Repository
CreateTestRepository creates a repository with specified attributes
func ExecCommand ¶
ExecCommand creates and runs an exec.Command with the given working directory. Common utility for all test packages needing to run git or shell commands.
func FakeCmd ¶
FakeCmd creates a minimal cobra.Command for testing with the given context and output writer.
func LoadFixture ¶
LoadFixture loads test configuration from the config package. The configPath parameter should be the relative path from the test file to the config directory (e.g., "../config", "../../config").
func SetupDirs ¶
SetupDirs creates repository directories to prevent cloning during tests. Automatically registers cleanup to remove the directories after the test.
func SetupFakeProvider ¶
func SetupFakeProvider(t *testing.T, _ context.Context, providerName string, project string) scm.Provider
SetupFakeProvider creates and registers a fake SCM provider with test data
func SetupFakeProviderWithRepos ¶
func SetupFakeProviderWithRepos(t *testing.T, _ context.Context, providerName string, project string, repos []*scm.Repository) scm.Provider
SetupFakeProviderWithRepos creates a fake provider with custom repositories
func SetupMultipleFakeProviders ¶
func SetupMultipleFakeProviders(t *testing.T, _ context.Context, projects []string) map[string]scm.Provider
SetupMultipleFakeProviders creates fake providers for multiple projects
func SetupRealProvider ¶
SetupRealProvider checks for credentials and skips test if not available This is used for optional integration tests against real SCM providers
Types ¶
type MockChannel ¶ added in v0.11.0
type MockChannel struct {
// contains filtered or unexported fields
}
MockChannel implements output.Channel for testing purposes. It provides a simple channel implementation that captures output and can be used to test call.Func implementations directly.
func NewMockChannel ¶ added in v0.11.0
func NewMockChannel(name string) *MockChannel
NewMockChannel creates a new MockChannel with the given name.
func (*MockChannel) Close ¶ added in v0.11.0
func (m *MockChannel) Close() error
Close is a no-op for the mock.
func (*MockChannel) Err ¶ added in v0.11.0
func (m *MockChannel) Err() <-chan error
Err returns nil (not used in mock).
func (*MockChannel) Error ¶ added in v0.11.0
func (m *MockChannel) Error() error
Error returns any captured error.
func (*MockChannel) Name ¶ added in v0.11.0
func (m *MockChannel) Name() string
Name returns the channel name.
func (*MockChannel) Out ¶ added in v0.11.0
func (m *MockChannel) Out() <-chan []byte
Out returns nil (not used in mock).
func (*MockChannel) Output ¶ added in v0.11.0
func (m *MockChannel) Output() []byte
Output returns the captured output.
func (*MockChannel) Start ¶ added in v0.11.0
func (m *MockChannel) Start(_ int64) error
Start is a no-op for the mock.
func (*MockChannel) Write ¶ added in v0.11.0
func (m *MockChannel) Write(p []byte) (int, error)
Write writes bytes to the mock output.
func (*MockChannel) WriteError ¶ added in v0.11.0
func (m *MockChannel) WriteError(err error)
WriteError stores an error in the mock.
func (*MockChannel) WriteString ¶ added in v0.11.0
func (m *MockChannel) WriteString(s string) (int, error)
WriteString writes a string to the mock output.