testutils

package
v1.20250907.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutils provides common testing utilities for the application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTableTests

func RunTableTests[T any, E any](t *testing.T, tests []TestCase, testFunc func(tc TestCase) (T, error))

RunTableTests runs a set of table-driven tests with standard error handling

func WriteJSON

func WriteJSON(w http.ResponseWriter, jsonStr string) error

WriteJSON writes the given JSON string to the ResponseWriter

Types

type GitHubServerOptions

type GitHubServerOptions struct {
	Owner           string
	Repo            string
	DefaultBranch   string
	WorkflowContent string
	SetupRepoInfo   bool
	SetupRefs       bool
	SetupContents   bool
	SetupBlobs      bool
	SetupTrees      bool
	SetupCommits    bool
	SetupPRs        bool
	SetupLabels     bool
	ErrorMode       string // Empty or one of: "repo", "branch", "contents", "blob", "pr"
}

GitHubServerOptions contains configuration for mock GitHub server setup

func DefaultServerOptions

func DefaultServerOptions(owner, repo string) *GitHubServerOptions

DefaultServerOptions returns standard options for a test server

type MockServerBuilder

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

MockServerBuilder helps build a mock HTTP server for testing GitHub API interactions

func NewMockServer

func NewMockServer() *MockServerBuilder

NewMockServer creates a new MockServerBuilder

func (*MockServerBuilder) Build

func (b *MockServerBuilder) Build() (*httptest.Server, *github.Client)

Build finalizes the server setup and returns the test server and a GitHub client

func (*MockServerBuilder) WithBlobHandler

func (b *MockServerBuilder) WithBlobHandler(owner, repo string) *MockServerBuilder

WithBlobHandler adds a handler for GitHub blob creation endpoint

func (*MockServerBuilder) WithCommitHandler

func (b *MockServerBuilder) WithCommitHandler(owner, repo string) *MockServerBuilder

WithCommitHandler adds a handler for GitHub commit creation endpoint

func (*MockServerBuilder) WithHandler

func (b *MockServerBuilder) WithHandler(path string, handler http.HandlerFunc) *MockServerBuilder

WithHandler adds a custom handler function to the mock server

func (*MockServerBuilder) WithJSONResponse

func (b *MockServerBuilder) WithJSONResponse(path string, statusCode int, responseBody string) *MockServerBuilder

WithJSONResponse adds a handler that returns a JSON response

func (*MockServerBuilder) WithLabelsHandler

func (b *MockServerBuilder) WithLabelsHandler(owner, repo string, issueNumber int) *MockServerBuilder

WithLabelsHandler adds a handler for GitHub labels endpoint

func (*MockServerBuilder) WithPRHandler

func (b *MockServerBuilder) WithPRHandler(owner, repo string) *MockServerBuilder

WithPRHandler adds a handler for GitHub pull request creation endpoint

func (*MockServerBuilder) WithRefHandler

func (b *MockServerBuilder) WithRefHandler(owner, repo, refName string, refResponse string) *MockServerBuilder

WithRefHandler adds a handler for GitHub reference endpoint

func (*MockServerBuilder) WithTreeHandler

func (b *MockServerBuilder) WithTreeHandler(owner, repo string) *MockServerBuilder

WithTreeHandler adds a handler for GitHub tree creation endpoint

type TestCase

type TestCase struct {
	Name     string
	Input    interface{}
	Expected interface{}
	Error    string
}

TestCase represents a generic test case structure

type TestFixture

type TestFixture struct {
	Server *httptest.Server
	Client *github.Client
	Mux    *http.ServeMux
}

TestFixture represents a reusable test fixture for GitHub API testing

func NewGitHubServerFixture

func NewGitHubServerFixture(options *GitHubServerOptions) *TestFixture

NewGitHubServerFixture creates a test fixture with a mock GitHub server

func (*TestFixture) ClientContext

func (f *TestFixture) ClientContext() context.Context

ClientContext returns a context for use with the client

func (*TestFixture) Close

func (f *TestFixture) Close()

Close shuts down the test server

func (*TestFixture) GitHubClientForFixture

func (f *TestFixture) GitHubClientForFixture() *github.Client

GitHubClientForFixture returns a GitHub client configured for the fixture

func (*TestFixture) SetupCustomHandler

func (f *TestFixture) SetupCustomHandler(path string, handler http.HandlerFunc)

SetupCustomHandler adds a custom handler to the mock server

Jump to

Keyboard shortcuts

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