Help us shape the future of Go! Take the 2026 Go Developer Survey

ghtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ghtest serves a fake GitHub REST API over httptest for tests. Handlers return recorded response shapes, so go-github's real request and decoding paths run.

Index

Constants

This section is empty.

Variables

View Source
var NotFound = Reply(http.StatusNotFound, map[string]string{"message": "Not Found"})

NotFound is GitHub's 404 body.

Functions

func JSON

func JSON(w http.ResponseWriter, status int, v any)

JSON writes v as a JSON response.

func Reply

func Reply(status int, v any) http.HandlerFunc

Reply returns a handler that always writes v.

Types

type Server

type Server struct {
	Mux    *http.ServeMux
	Client *github.Client
	// contains filtered or unexported fields
}

Server is a fake GitHub API. Register handlers on Mux with paths like "GET /repos/o/r/pulls/1".

func New

func New(t *testing.T) *Server

New starts a server and returns a client pointed at it.

func (*Server) Requests

func (s *Server) Requests() []string

Requests returns "METHOD /path" for each request served so far.

func (*Server) Reset

func (s *Server) Reset()

Reset forgets the requests served so far.

Jump to

Keyboard shortcuts

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