testutil

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileContains

func AssertFileContains(t *testing.T, path, expected string)

AssertFileContains asserts that a file contains a specific string

func AssertFileExists

func AssertFileExists(t *testing.T, path string)

AssertFileExists asserts that a file exists

func AssertFileNotExists

func AssertFileNotExists(t *testing.T, path string)

AssertFileNotExists asserts that a file does not exist

func AssertGitConfigContains

func AssertGitConfigContains(t *testing.T, dir, key, expectedSubstring string)

AssertGitConfigContains asserts that git config contains a specific entry

func AssertGitConfigNotExists

func AssertGitConfigNotExists(t *testing.T, dir, key string)

AssertGitConfigNotExists asserts that a git config key does not exist

func BuildBinary

func BuildBinary(t *testing.T) string

BuildBinary builds the gh-app-auth binary for testing

func CleanupTestConfig

func CleanupTestConfig(t *testing.T, configPath string)

CleanupTestConfig cleans up test configuration

func CreateMultiOrgConfig

func CreateMultiOrgConfig(t *testing.T) string

CreateMultiOrgConfig creates a config with multiple organizations

func CreateSimpleConfig

func CreateSimpleConfig(t *testing.T) string

CreateSimpleConfig creates a simple config with one app

func CreateTempConfig

func CreateTempConfig(t *testing.T, apps []config.GitHubApp) string

CreateTempConfig creates a temporary config file

func CreateTestPrivateKey

func CreateTestPrivateKey(t *testing.T) string

CreateTestPrivateKey creates a test private key file

func GetGitConfig

func GetGitConfig(t *testing.T, dir, key string) (string, error)

GetGitConfig gets a git config value

func InitGitRepo

func InitGitRepo(t *testing.T, dir string)

InitGitRepo initializes a git repository in the given directory

func ListGitConfigs

func ListGitConfigs(t *testing.T, dir, pattern string) []string

ListGitConfigs lists all git configs matching a pattern

func RequireEnvVar

func RequireEnvVar(t *testing.T, name string) string

RequireEnvVar requires that an environment variable is set

func RequireGit

func RequireGit(t *testing.T)

RequireGit skips the test if git is not available

func SetGitConfig

func SetGitConfig(t *testing.T, dir, key, value string)

SetGitConfig sets a git config value

func SetupTestConfig

func SetupTestConfig(t *testing.T, apps []config.GitHubApp) string

SetupTestConfig sets up a test config and returns the path

func SkipIfShort

func SkipIfShort(t *testing.T, reason string)

SkipIfShort skips the test if running in short mode

Types

type ConfigBuilder

type ConfigBuilder struct {
	// contains filtered or unexported fields
}

ConfigBuilder helps build test configurations

func NewConfigBuilder

func NewConfigBuilder() *ConfigBuilder

NewConfigBuilder creates a new config builder

func (*ConfigBuilder) AddApp

func (cb *ConfigBuilder) AddApp(app config.GitHubApp) *ConfigBuilder

AddApp adds a GitHub App to the configuration

func (*ConfigBuilder) AddSimpleApp

func (cb *ConfigBuilder) AddSimpleApp(name string, appID int64, patterns []string) *ConfigBuilder

AddSimpleApp adds a simple app with basic configuration

func (*ConfigBuilder) Build

func (cb *ConfigBuilder) Build() *config.Config

Build creates the config

func (*ConfigBuilder) WriteToFile

func (cb *ConfigBuilder) WriteToFile(t *testing.T, path string) string

WriteToFile writes the config to a file

type ErrorMode

type ErrorMode int

ErrorMode controls error simulation

const (
	ErrorNone ErrorMode = iota
	Error401Unauthorized
	Error403Forbidden
	Error404NotFound
	Error500ServerError
	ErrorTimeout
)

type JWTValidationBehavior

type JWTValidationBehavior int

JWTValidationBehavior controls JWT validation behavior

const (
	JWTAcceptAll JWTValidationBehavior = iota
	JWTRejectAll
	JWTValidateFormat
)

type MockGitHubServer

type MockGitHubServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

MockGitHubServer provides a mock GitHub API server for testing

func NewMockGitHubServer

func NewMockGitHubServer(t *testing.T) *MockGitHubServer

NewMockGitHubServer creates a new mock GitHub API server

func (*MockGitHubServer) Close

func (m *MockGitHubServer) Close()

Close shuts down the mock server

func (*MockGitHubServer) GetURL

func (m *MockGitHubServer) GetURL() string

GetURL returns the base URL of the mock server

func (*MockGitHubServer) SetErrorMode

func (m *MockGitHubServer) SetErrorMode(mode ErrorMode)

SetErrorMode sets the error simulation mode

func (*MockGitHubServer) SetInstallationToken

func (m *MockGitHubServer) SetInstallationToken(installationID, token string)

SetInstallationToken configures a token for a specific installation

func (*MockGitHubServer) SetJWTValidation

func (m *MockGitHubServer) SetJWTValidation(behavior JWTValidationBehavior)

SetJWTValidation sets the JWT validation behavior

Jump to

Keyboard shortcuts

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