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
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 ¶
This section is empty.