githubtest

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 7 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 (
	CodeScanningNotEnabled = `{"message": "Code scanning is not enabled for this repository. Please enable code scanning ` +
		`in the repository settings.", "documentation_url": "https://docs.github.com/rest/code-scanning/code-scanning", ` +
		`"status": "403"}`
	CodeScanningNoAnalysis = `{"message": "no analysis found", "documentation_url": ` +
		`"https://docs.github.com/rest/code-scanning/code-scanning", "status": "404"}`
	SecretScanningDisabled = `{"message": "Secret scanning is disabled on this repository.", "documentation_url": ` +
		`"https://docs.github.com/rest/secret-scanning/secret-scanning", "status": "404"}`
	AlertsNotAccessible = `{"message": "Resource not accessible by personal access token", "documentation_url": ` +
		`"https://docs.github.com/rest/code-scanning/code-scanning", "status": "403"}`
	RepositoryNotFound = `{"message": "Not Found", "documentation_url": "https://docs.github.com/rest", "status": "404"}`
)

GitHub's bodies for a scanning read it refuses, with the status each comes with: code scanning off (403) or never analyzed (404), secret scanning off (404), the alerts refused to an account without access (403), and a repository it can't find (404). The probes of November 2026 measured the first words of the two that say a feature is off ("Code scanning is not enabled", "Secret scanning is disabled"); the rest is written by hand.

View Source
const LeakedSecret = "QZJX-QZJX-QZJX-QZJX-QZJX-QZJX" //nolint:gosec // a fixture's fake secret, no credential

LeakedSecret is the secret SecretScanningAnswer's first alert holds, as GitHub sends it when a read leaves out hide_secret=true. No part of it may survive a read: the client never decodes it.

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.

func CodeScanningAnswer

func CodeScanningAnswer() []byte

CodeScanningAnswer is GitHub's answer to a CodeScanningAlerts read of acme-org/example-repo: a CodeQL alert of high security severity, and an OSV-Scanner alert from an uploaded SARIF file, whose rule gives no security severity.

func GenericSecretScanningAnswer

func GenericSecretScanningAnswer() []byte

GenericSecretScanningAnswer is GitHub's answer to a secret scanning read of acme-org/example-repo that names the generic types (github.GenericSecretTypes), sent without hide_secret=true: its first alert, a password whose validity GitHub can't check, holds LeakedSecret, and its second, a high-entropy string, holds none. Neither has a validity GitHub can check, as generic secrets' never do.

func SecretScanningAnswer

func SecretScanningAnswer() []byte

SecretScanningAnswer is GitHub's answer to a secret scanning read of acme-org/example-repo sent without hide_secret=true: its first alert, an active token pushed past push protection and found in more places, holds LeakedSecret, and its second, an inactive webhook URL leaked in public and in other repositories, found in an issue's title, holds none.

func SecurityAlertsAnswer

func SecurityAlertsAnswer() []byte

SecurityAlertsAnswer is GitHub's answer to one SecurityAlerts query about SecurityRepos, with SecurityFixBranches and SecurityPullNumbers. Its first repository's alerts are a high one on a runtime dependency with Dependabot's pull request open, its checks failing, a critical one on a development dependency Dependabot couldn't update, and a low one with no patched version and nothing from Dependabot; its fix branches' pull requests are a merged one, its checks passing and approved, and an open one, its checks running and its review required.

func SecurityFixBranches

func SecurityFixBranches() map[string][]string

SecurityFixBranches are the fix branches SecurityAlertsAnswer answers, by repository key: acme-org/example-repo's merged fix, its open one, and one with no pull request yet (f0 to f2), and octo-user/busy-repo's, whose newest pull request is a fork's (f0).

func SecurityPullNumbers

func SecurityPullNumbers() map[string][]int

SecurityPullNumbers are the pull requests SecurityAlertsAnswer answers by number, by repository key: acme-org/example-repo's Dependabot pull request #12, open, its checks failing, which its alert still names; #13, merged, which no alert's update names any more; and #404, which GitHub can't find (p0 to p2).

func SecurityRepos

func SecurityRepos() []repo.Name

SecurityRepos are the repositories SecurityAlertsAnswer answers, in the order a SecurityAlerts read of them asks (r0 to r7, each with its setting under e0 to e7): one with three open alerts and fix branches; one archived with Dependabot alerts off; one GitHub can't resolve; one whose alerts GitHub refuses; one with more open alerts than the read lists, whose setting GitHub refuses; one behind an organization's SAML single sign-on; one GitHub answered in part, an alert of it null with an error; and one whose alerts GitHub refuses for want of a scope.

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