Documentation
¶
Overview ¶
Package testutils provides common testing utilities for the application
Index ¶
- func RunTableTests[T any, E any](t *testing.T, tests []TestCase, testFunc func(tc TestCase) (T, error))
- func WriteJSON(w http.ResponseWriter, jsonStr string) error
- type GitHubServerOptions
- type MockServerBuilder
- func (b *MockServerBuilder) Build() (*httptest.Server, *github.Client)
- func (b *MockServerBuilder) WithBlobHandler(owner, repo string) *MockServerBuilder
- func (b *MockServerBuilder) WithCommitHandler(owner, repo string) *MockServerBuilder
- func (b *MockServerBuilder) WithHandler(path string, handler http.HandlerFunc) *MockServerBuilder
- func (b *MockServerBuilder) WithJSONResponse(path string, statusCode int, responseBody string) *MockServerBuilder
- func (b *MockServerBuilder) WithLabelsHandler(owner, repo string, issueNumber int) *MockServerBuilder
- func (b *MockServerBuilder) WithPRHandler(owner, repo string) *MockServerBuilder
- func (b *MockServerBuilder) WithRefHandler(owner, repo, refName string, refResponse string) *MockServerBuilder
- func (b *MockServerBuilder) WithTreeHandler(owner, repo string) *MockServerBuilder
- type TestCase
- type TestFixture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 TestFixture ¶
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) 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