renderror

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(rendC *render.Render) func(http.Handler) http.Handler

Handler is middleware that renders error pages based on response status codes

Types

type RenderClient

type RenderClient interface {
	BuildHTML(w io.Writer, status int, templateName string, pageModel interface{}) error
	SetError(w io.Writer, status int, errorModel model.ErrorResponse) error
}

type RenderClientMock

type RenderClientMock struct {
	// BuildHTMLFunc mocks the BuildHTML method.
	BuildHTMLFunc func(w io.Writer, status int, templateName string, pageModel interface{}) error

	// SetErrorFunc mocks the SetError method.
	SetErrorFunc func(w io.Writer, status int, errorModel model.ErrorResponse) error
	// contains filtered or unexported fields
}

RenderClientMock is a mock implementation of RenderClient.

    func TestSomethingThatUsesRenderClient(t *testing.T) {

        // make and configure a mocked RenderClient
        mockedRenderClient := &RenderClientMock{
            BuildHTMLFunc: func(w io.Writer, status int, templateName string, pageModel interface{}) error {
	               panic("mock out the BuildHTML method")
            },
            SetErrorFunc: func(w io.Writer, status int, errorModel model.ErrorResponse) error {
	               panic("mock out the SetError method")
            },
        }

        // use mockedRenderClient in code that requires RenderClient
        // and then make assertions.

    }

func (*RenderClientMock) BuildHTML

func (mock *RenderClientMock) BuildHTML(w io.Writer, status int, templateName string, pageModel interface{}) error

BuildHTML calls BuildHTMLFunc.

func (*RenderClientMock) BuildHTMLCalls

func (mock *RenderClientMock) BuildHTMLCalls() []struct {
	W            io.Writer
	Status       int
	TemplateName string
	PageModel    interface{}
}

BuildHTMLCalls gets all the calls that were made to BuildHTML. Check the length with:

len(mockedRenderClient.BuildHTMLCalls())

func (*RenderClientMock) SetError

func (mock *RenderClientMock) SetError(w io.Writer, status int, errorModel model.ErrorResponse) error

SetError calls SetErrorFunc.

func (*RenderClientMock) SetErrorCalls

func (mock *RenderClientMock) SetErrorCalls() []struct {
	W          io.Writer
	Status     int
	ErrorModel model.ErrorResponse
}

SetErrorCalls gets all the calls that were made to SetError. Check the length with:

len(mockedRenderClient.SetErrorCalls())

Jump to

Keyboard shortcuts

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