githubtest

package
v0.0.0-...-610d9af Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: GPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githubtest is a minimal fake of GitHub's OAuth and REST endpoints for tests. It is a real HTTP server (httptest), so the production client code (auth.GitHub) runs unchanged; only its three base URLs are redirected here. It also VERIFIES PKCE, so a test fails if the client forgets to send the challenge or the verifier.

Endpoints: GET /login/oauth/authorize, POST /login/oauth/access_token, GET /api/user, GET /api/user/emails.

Index

Constants

View Source
const (
	ClientID     = "test-client-id"
	ClientSecret = "test-client-secret"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

type Email struct {
	Email    string `json:"email"`
	Primary  bool   `json:"primary"`
	Verified bool   `json:"verified"`
}

Email is one entry of GET /user/emails.

type Server

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

Server is the fake. Change User (via SetUser) between flows to simulate different people.

func New

func New(tb testing.TB) *Server

New starts the fake and stops it when the test ends.

func (*Server) Config

func (s *Server) Config(redirectURL string) auth.GitHubConfig

Config returns an auth.GitHubConfig whose URLs point at the fake.

func (*Server) SetUser

func (s *Server) SetUser(u User)

SetUser sets the account the fake reports from now on.

type User

type User struct {
	ID        int64
	Login     string
	Name      string
	AvatarURL string
	Emails    []Email
}

User is the GitHub account the fake will report.

Jump to

Keyboard shortcuts

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