httpmock

package
v1.205.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitHubMockServer

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

GitHubMockServer intercepts GitHub requests and serves mock content. It provides a mock HTTP server that can be used to replace real GitHub raw content requests in tests, avoiding network dependencies and rate limits.

func NewGitHubMockServer

func NewGitHubMockServer(t *testing.T) *GitHubMockServer

NewGitHubMockServer creates a mock server that intercepts GitHub requests. The server is automatically cleaned up when the test completes.

func (*GitHubMockServer) HTTPClient

func (m *GitHubMockServer) HTTPClient() *http.Client

HTTPClient returns an http.Client that intercepts GitHub URLs. Use this with go-getter's HttpGetter or any HTTP client that needs to have GitHub requests redirected to the mock server.

func (*GitHubMockServer) HttpGetter

func (m *GitHubMockServer) HttpGetter() *getter.HttpGetter

HttpGetter returns a go-getter HttpGetter configured to use the mock. Use this when you need to inject a custom getter into go-getter's client.

func (*GitHubMockServer) RegisterFile

func (m *GitHubMockServer) RegisterFile(pathSuffix, content string)

RegisterFile registers content to be served for a given path suffix. The path suffix is matched against the end of incoming request paths. For example, RegisterFile("stacks/deploy/nonprod.yaml", content) will match requests to /cloudposse/atmos/main/tests/fixtures/scenarios/stack-templates-2/stacks/deploy/nonprod.yaml.

func (*GitHubMockServer) Transport

func (m *GitHubMockServer) Transport() http.RoundTripper

Transport returns an http.RoundTripper that intercepts GitHub URLs. Can be used to replace http.DefaultTransport in tests to intercept all HTTP requests to GitHub without modifying the code under test.

func (*GitHubMockServer) URL

func (m *GitHubMockServer) URL() string

URL returns the mock server URL.

Jump to

Keyboard shortcuts

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