testing

package
v0.10.0 Latest Latest
Warning

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

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

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

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

func AssertContains(t *testing.T, got any, want any, index ...int)

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

func AssertEqual(t *testing.T, got, want any)

AssertEqual verifies two values are equal.

func AssertError

func AssertError(t *testing.T, err error, wantErr bool)

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

func AssertLength(t *testing.T, got any, want int)

AssertLength verifies the length of a string, slice, or map using reflection.

func AssertNotContains

func AssertNotContains(t *testing.T, output any, unwanted []string)

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

func AssertNotEmpty(t *testing.T, got string)

AssertNotEmpty verifies a string is not empty.

func AssertOutput

func AssertOutput(t *testing.T, got, want []string, err error, wantErr bool)

AssertOutput validates test output and error against expected values.

func AssertRepositoryExists

func AssertRepositoryExists(t *testing.T, catalog map[string]scm.Repository, repoKey string)

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

func ExecCommand(t *testing.T, dir string, name string, args ...string)

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

func FakeCmd(t *testing.T, ctx context.Context, out io.Writer) *cobra.Command

FakeCmd creates a minimal cobra.Command for testing with the given context and output writer.

func LoadFixture

func LoadFixture(t *testing.T, configPath string) context.Context

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

func SetupDirs(t *testing.T, ctx context.Context, repos []string)

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

func SetupRealProvider(t *testing.T, ctx context.Context, providerName string)

SetupRealProvider checks for credentials and skips test if not available This is used for optional integration tests against real SCM providers

func SetupRepos

func SetupRepos(t *testing.T, repos []string, branches ...bool) string

SetupRepos creates git repositories that mimic real git workflow. Creates a shared bare origin repository and clones from it. Tests are responsible for creating their own branches as needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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