github_ratelimit_test

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidBodyContent = `{"message": "not as expected"}`
)
View Source
const (
	SecondaryRateLimitMessage = `You have exceeded a secondary rate limit. Please wait a few minutes before you try again.`
)

Variables

View Source
var SecondaryRateLimitDocumentationURLs = []string{
	`https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits`,
	`https://docs.github.com/free-pro-team@latest/rest/overview/resources-in-the-rest-api#secondary-rate-limits`,
	`https://docs.github.com/en/free-pro-team@latest/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits`,
	`https://docs.github.com/en/some-other-option#abuse-rate-limits`,
}

Functions

func GetRandomStatusCode

func GetRandomStatusCode() int

func IsInvalidBody

func IsInvalidBody(resp *http.Response) (bool, error)

func NewPrimaryClient

func NewPrimaryClient(base http.RoundTripper, opts ...github_primary_ratelimit.Option) *http.Client

func NewRateLimitInjecter

func NewRateLimitInjecter(base http.RoundTripper, options *RateLimitInjecterOptions) (http.RoundTripper, error)

func NewSecondaryClient

func NewSecondaryClient(base http.RoundTripper, opts ...github_secondary_ratelimit.Option) *http.Client

func SetupInjecterWithOptions

func SetupInjecterWithOptions(t *testing.T, options RateLimitInjecterOptions, roundTrippger http.RoundTripper) http.RoundTripper

func SetupSecondaryInjecter

func SetupSecondaryInjecter(t *testing.T, every time.Duration, sleep time.Duration) http.RoundTripper

func UpTo1SecDelay

func UpTo1SecDelay() time.Duration

func WaitForNextSleep

func WaitForNextSleep(injecter http.RoundTripper)

Types

type RateLimitInjecter

type RateLimitInjecter struct {
	Base http.RoundTripper

	AbuseAttempts int
	// contains filtered or unexported fields
}

func (*RateLimitInjecter) RoundTrip

func (t *RateLimitInjecter) RoundTrip(request *http.Request) (*http.Response, error)

func (*RateLimitInjecter) WaitForNextInjection

func (r *RateLimitInjecter) WaitForNextInjection()

type RateLimitInjecterOptions

type RateLimitInjecterOptions struct {
	Every                    time.Duration
	InjectionDuration        time.Duration
	InvalidBody              bool
	UseXRateLimit            bool
	UsePrimaryRateLimit      bool
	DocumentationURL         string
	HttpStatusCode           int
	PrimaryRateLimitCategory github_primary_ratelimit.ResourceCategory
}

RateLimitInjecterOptions provide options for the injection. note: Every is the interval between the start of two rate limit injections. It is first counted from the first request, then counted from the end of the last injection.

func (*RateLimitInjecterOptions) IsNoop

func (r *RateLimitInjecterOptions) IsNoop() bool

func (*RateLimitInjecterOptions) Validate

func (r *RateLimitInjecterOptions) Validate() error

Jump to

Keyboard shortcuts

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