routertest

package
v1.84.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerMock

type HandlerMock struct {
	// ServeHTTPFunc mocks the ServeHTTP method.
	ServeHTTPFunc func(in1 http.ResponseWriter, in2 *http.Request)
	// contains filtered or unexported fields
}

HandlerMock is a mock implementation of router.Handler.

    func TestSomethingThatUsesHandler(t *testing.T) {

        // make and configure a mocked router.Handler
        mockedHandler := &HandlerMock{
            ServeHTTPFunc: func(in1 http.ResponseWriter, in2 *http.Request)  {
	               panic("mock out the ServeHTTP method")
            },
        }

        // use mockedHandler in code that requires router.Handler
        // and then make assertions.

    }

func (*HandlerMock) ServeHTTP

func (mock *HandlerMock) ServeHTTP(in1 http.ResponseWriter, in2 *http.Request)

ServeHTTP calls ServeHTTPFunc.

func (*HandlerMock) ServeHTTPCalls

func (mock *HandlerMock) ServeHTTPCalls() []struct {
	In1 http.ResponseWriter
	In2 *http.Request
}

ServeHTTPCalls gets all the calls that were made to ServeHTTP. Check the length with:

len(mockedHandler.ServeHTTPCalls())

Jump to

Keyboard shortcuts

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