reqresp

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package reqresp is used to create mock web servers for testing

Index

Constants

This section is empty.

Variables

View Source
var BaseEntries = []ReqResp{
	{
		ReqEntry: ReqEntry{
			Method: "GET",
			Path:   "/v2/",
		},
		RespEntry: RespEntry{
			Status: http.StatusOK,
			Headers: http.Header(map[string][]string{
				"Docker-Distribution-API-Version": {"registry/2.0"},
			}),
		},
	},
}

BaseEntries initial entries for a generic docker registry

Functions

func NewHandler

func NewHandler(t *testing.T, rrs []ReqResp) http.Handler

func NewRandomBlob

func NewRandomBlob(size int, seed int64) (digest.Digest, []byte)

NewRandomBlob outputs a reproducible random blob (based on the seed) for testing

func NewRandomID added in v0.6.0

func NewRandomID(seed int64) string

NewRandomID outputs a reproducible random ID (based on the seed) appropriate for blob upload URLs.

Types

type ReqEntry

type ReqEntry struct {
	Name     string
	DelOnUse bool
	IfState  []string
	SetState string
	Method   string
	Path     string
	PathRE   *regexp.Regexp
	Query    map[string][]string
	Headers  http.Header
	Body     []byte
}

type ReqResp

type ReqResp struct {
	ReqEntry  ReqEntry
	RespEntry RespEntry
}

type RespEntry

type RespEntry struct {
	Status  int
	Headers http.Header
	Body    []byte
	Fail    bool // triggers a handler panic that simulates a server/connection failure
}

Jump to

Keyboard shortcuts

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