helpers

package
v0.0.0-...-ba26d65 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DummyMachineID = "dummy-machine-id"
	DummyAgentID   = "779cdd70-e9e2-58ca-b18a-bf3eb3f71244"
)

Variables

This section is empty.

Functions

func GetFixturePath

func GetFixturePath(name string) string

func MockMachineIDFile

func MockMachineIDFile() afero.Fs

MockMachineIDFile mocks the /etc/machine-id file to have a known value

Types

type ErroringRoundTripFunc

type ErroringRoundTripFunc func() error

ErroringRoundTripFunc Needed to Mock Http client that returns an error even before the request is made

Usage

&http.Client{
	 Transport: helpers.ErroringRoundTripFunc(func() error {
	 	return fmt.Errorf("some error")
	 }),
}

func (ErroringRoundTripFunc) RoundTrip

func (f ErroringRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

ErroringRoundTripFunc implements the RoundTripper interface

type RoundTripFunc

type RoundTripFunc func(req *http.Request) *http.Response

RoundTripFunc Needed to Mock Http client requests and responses

Usage

&http.Client{
	 Transport: helpers.RoundTripFunc(func(req *http.Request) *http.Response {
	    bodyBytes, _ := ioutil.ReadAll(req.Body)

	 	suite.EqualValues(expectedBody, string(bodyBytes))

	 	suite.Equal(req.URL.String(), expectedUrl)
	 	return &http.Response{
			StatusCode: returnedStatusCode,
	 	}
    }),
}

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTripFunc implements the RoundTripper interface

Jump to

Keyboard shortcuts

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