githubtest

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 4 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 holds the fakes of internal/github that the test suites share: a token source that never reaches GitHub, the bookkeeping of a fake GitHub's requests, and GitHub's refusal of a token. internal/testutil cannot hold them, as internal/github imports it. Only tests may import this package.

Index

Constants

View Source
const Token = "test-token-not-real"

Token is the token a Tokens lends when it was given none: it never reaches GitHub.

Variables

This section is empty.

Functions

func BadCredentials

func BadCredentials() error

BadCredentials is GitHub refusing the token.

Types

type Calls

type Calls struct {
	// contains filtered or unexported fields
}

Calls counts a fake GitHub's requests by name and keeps their order. Its zero value is ready to use, and it is safe for concurrent use.

func (*Calls) Add

func (c *Calls) Add(name string)

Add records a request named name.

func (*Calls) Count

func (c *Calls) Count(name string) int

Count returns how many requests named name were made.

func (*Calls) Len

func (c *Calls) Len() int

Len returns how many requests were made, whatever their names.

func (*Calls) Since

func (c *Calls) Since(names ...string) []string

Since names the requests made after the last one named any of names, in order: every request when none of names was made.

type Tokens

type Tokens struct {
	// contains filtered or unexported fields
}

Tokens is a token source that lends tokens in turn and records the ones it is told to forget. It is safe for concurrent use; a test reads it with Loans and Forgot once the calls it made have returned.

func FailingTokens

func FailingTokens(errs []error, values ...string) *Tokens

FailingTokens returns Tokens whose loans fail in turn with errs, a nil error lending values as NewTokens does, and every loan after the last of errs lending a token.

func NewTokens

func NewTokens(values ...string) *Tokens

NewTokens returns Tokens that lend values in turn, the last of them again once the rest are lent, or Token when there are none.

func (*Tokens) Fail

func (f *Tokens) Fail(err error)

Fail makes every loan from now on fail with err, or lend again for nil.

func (*Tokens) Forget

func (f *Tokens) Forget(tok github.Token)

Forget records tok as given back, as GitHub refused it.

func (*Tokens) Forgot

func (f *Tokens) Forgot() []string

Forgot returns the tokens given back, in order.

func (*Tokens) Loans

func (f *Tokens) Loans() int

Loans returns how many tokens were asked for, the failed loans among them.

func (*Tokens) Swap

func (f *Tokens) Swap(value string)

Swap lends value from now on, as gh auth switch does.

func (*Tokens) Token

func (f *Tokens) Token(ctx context.Context) (github.Token, error)

Token lends the next token. A loan counts even when it fails: on a context that is done, with its error; with the loan's own error from FailingTokens; or with the error Fail set.

Jump to

Keyboard shortcuts

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