testutil

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides httptest-based API mocking utilities for testing commands that interact with the Google Play Android Publisher API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditFixture

func EditFixture() map[string]interface{}

EditFixture returns a sample Edits.insert / Edits.get response.

func ErrorFixture403

func ErrorFixture403() map[string]interface{}

ErrorFixture403 returns a Google-style 403 error response body.

func ErrorFixture404

func ErrorFixture404() map[string]interface{}

ErrorFixture404 returns a Google-style 404 error response body.

func ErrorFixture409

func ErrorFixture409() map[string]interface{}

ErrorFixture409 returns a Google-style 409 error response body.

func HandleError

func HandleError(statusCode int, message string) http.HandlerFunc

HandleError returns an http.HandlerFunc that responds with a Google-style JSON error body.

func HandleJSON

func HandleJSON(statusCode int, body interface{}) http.HandlerFunc

HandleJSON returns an http.HandlerFunc that responds with the given status code and JSON-encodes body into the response.

func IsolateConfig

func IsolateConfig(t *testing.T) string

IsolateConfig sets GPLAY_CONFIG_PATH to a fresh temp directory and registers cleanup.

func ListingFixture

func ListingFixture() map[string]interface{}

ListingFixture returns a sample Listings.get response.

func ListingsListFixture

func ListingsListFixture() map[string]interface{}

ListingsListFixture returns a sample Listings.list response.

func MockServiceAccount

func MockServiceAccount(t *testing.T) string

MockServiceAccount creates a fake but structurally valid service account JSON file.

func RequireEnv

func RequireEnv(t *testing.T, key string) string

RequireEnv skips the test if the named env var is not set, otherwise returns its value.

func ReviewFixture

func ReviewFixture() map[string]interface{}

ReviewFixture returns a sample Reviews.get response.

func ReviewsListFixture

func ReviewsListFixture() map[string]interface{}

ReviewsListFixture returns a sample Reviews.list response.

func SkipUnlessIntegration

func SkipUnlessIntegration(t *testing.T)

SkipUnlessIntegration skips the test unless GPLAY_INTEGRATION_TEST is set to "1" or "true".

func TrackFixture

func TrackFixture() map[string]interface{}

TrackFixture returns a sample Tracks.get response with a single release.

func TracksListFixture

func TracksListFixture() map[string]interface{}

TracksListFixture returns a sample Tracks.list response.

Types

type MockAPI

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

MockAPI wraps an httptest.Server with request logging and convenience helpers.

func NewMockAPI

func NewMockAPI(t *testing.T, handlers map[string]http.HandlerFunc) *MockAPI

NewMockAPI creates a new test server routing requests through the given handler map. Keys are "METHOD /path" (e.g. "GET /edits"). Unmatched requests receive a 404 response. Every request is recorded in the log. The server is automatically closed via t.Cleanup.

func (*MockAPI) BaseURL

func (m *MockAPI) BaseURL() string

BaseURL returns the test server's URL (e.g. "http://127.0.0.1:PORT").

func (*MockAPI) RequestLog

func (m *MockAPI) RequestLog() []RequestEntry

RequestLog returns a copy of all recorded requests.

type RequestEntry

type RequestEntry struct {
	Method string
	Path   string
	Body   string
}

RequestEntry records a single HTTP request received by the mock server.

Jump to

Keyboard shortcuts

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