testutil

package
v0.0.0-...-3f413d8 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil implements a fake ECS client to be used in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyECS

type DummyECS struct {
	Requests     chan *http.Request
	RequestCount atomic.Uint64
	// contains filtered or unexported fields
}

DummyECS allows tests to mock ECS metadata server responses

func NewDummyECS

func NewDummyECS(ops ...Option) (*DummyECS, error)

NewDummyECS create a mock of the ECS metadata API.

func (*DummyECS) ServeHTTP

func (d *DummyECS) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is used to handle HTTP requests.

func (*DummyECS) Start

func (d *DummyECS) Start() *httptest.Server

Start starts the HTTP server

type Option

type Option func(*DummyECS)

Option represents an option used to create a new mock of the ECS metadata server.

func FileHandlerDelayOption

func FileHandlerDelayOption(pattern string, delay time.Duration) Option

FileHandlerDelayOption allows returning to requests matching a pattern with a delay.

func FileHandlerOption

func FileHandlerOption(pattern, testDataFile string) Option

FileHandlerOption allows returning the content of a file to requests matching a pattern.

func RawHandlerDelayOption

func RawHandlerDelayOption(pattern string, delay time.Duration) Option

RawHandlerDelayOption allows returning to requests matching a pattern with a delay.

func RawHandlerOption

func RawHandlerOption(pattern, rawResponse string) Option

RawHandlerOption allows returning the specified string to requests matching a pattern.

Jump to

Keyboard shortcuts

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