mock

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

* Package mock provides an httptest.Server that allows mock interactions with the * Sectigo API for both unit tests of the Sectigo package and integration tests with GDS * Sectigo/Certificate operations. * * The basic use case is to create a *mock.Server using mock.New(). Requests to the * mock server endpoint (fetched using mock.Server.URL()) will return "happy path" * responses for a single fake certificate interaction. You can also modify the response * from the mock server by using mock.Handle or one of the handler methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(endpoint string, handler gin.HandlerFunc) error

Handle is a helper function that adds a handler to the mock server's handlers map and returns that handler function when the endpoint is called.

func Start

func Start(profile string) error

Start() initializes a new server which mocks the Sectigo REST API. By default, it sets up HTTP handlers which return 200 OK responses with mocked data, but custom handlers can be passed in by tests to test specific error paths. Note that this function modifies the externally used baseURL for the Sectigo endpoint, and the caller must call Stop() to close the server and undo the mock when done. Start() takes one paramter, which is the name of the sectigo profile that the mock server uses to verify request parameters in createSingleCertBatch.

func Stop

func Stop()

Stop the test server and reset the Sectigo server URL to complete the tests and cleanup.

Types

type Profile added in v1.3.1

type Profile struct {
	ID      string
	Name    string
	Balance int
	Params  []ProfileParam
}

type ProfileParam added in v1.5.1

type ProfileParam struct {
	Name     string
	Validate validationFunc
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server helps verify that the success paths of the Sectigo API calls are working, while also providing a way for tests to inject handlers to test the errors that might be returned from the Sectigo API.

func Get

func Get() *Server

Get returns the current mock server.

func (*Server) GetCalls

func (s *Server) GetCalls() sync.Map

GetCalls returns the map of called endpoints.

func (*Server) URL

func (s *Server) URL() *url.URL

URL returns the URL of the test server.

Jump to

Keyboard shortcuts

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