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
- func BadCredentials() error
- func CodeScanningAnswer() []byte
- func GenericSecretScanningAnswer() []byte
- func SecretScanningAnswer() []byte
- func SecurityAlertsAnswer() []byte
- func SecurityFixBranches() map[string][]string
- func SecurityPullNumbers() map[string][]int
- func SecurityRepos() []repo.Name
- type Calls
- type Tokens
Constants ¶
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.
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.
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 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 ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
NewTokens returns Tokens that lend values in turn, the last of them again once the rest are lent, or Token when there are none.