http

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockRequestSimple

func MockRequestSimple(ctx context.Context, server, httpPath string, status int, body string) error

MockRequestSimple mocks a HTTP request by sending a command to the HTTP mock server. It only configures the request path, the response status code and the response body. The "application/json" content type is applied implicitly to the response.

Types

type MockRequest

type MockRequest struct {
	// Permanent is true if the configuration is permanent.
	// If permanent is false, the mockRequest is removed after matching the first request.
	Permanent bool     `json:"permanent"`
	Request   Request  `json:"request"`
	Response  Response `json:"response"`
	// Latency is the duration in milliseconds to wait to deliver the response.
	// If 0, there is no latency to apply.
	// If negative, there will be no response (timeout simulation).
	Latency int `json:"latency"`
}

MockRequest contains the instruction to configure the behavior of the HTTP mock server. The document configures which request is going to be attended (e.g. the path and method) and the response to be generated by the mock.

func (MockRequest) String

func (m MockRequest) String() string

type MockRequests

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

func (*MockRequests) CleanMockRequests

func (m *MockRequests) CleanMockRequests()

CleanMockRequests removes all the mockRequests from the list.

func (*MockRequests) MatchMockRequest

func (m *MockRequests) MatchMockRequest(r *http.Request) *MockRequest

MatchMockRequest finds the first mockRequest matching the HTTP request.

func (*MockRequests) PushMockRequest

func (m *MockRequests) PushMockRequest(mockRequest *MockRequest)

PushMockRequest adds a MockRequest to the list.

func (*MockRequests) RemoveMockRequest

func (m *MockRequests) RemoveMockRequest(mockRequest *MockRequest) bool

Remove a mockRequest. It returns true if it was found and removed.

type Request

type Request struct {
	Method  string              `json:"method,omitempty"`
	Path    string              `json:"path,omitempty"`
	Headers map[string][]string `json:"headers,omitempty"`
}

Request configures the filter for the request of the MockRequest.

type Response

type Response struct {
	Status  int                 `json:"status"`
	Headers map[string][]string `json:"headers"`
	Body    string              `json:"body"`
}

Response configures which response if the request filter applies.

type Server

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

Server type for the HTTP mock server.

func NewServer

func NewServer(port int) *Server

NewServer creates an instance of Server.

func (*Server) Start

func (s *Server) Start() error

Start the HTTP mock server. Note that it blocks the current goroutine with http.ListenAndServe function.

type Steps

type Steps struct {
}

Steps to initialize common steps.

func (Steps) InitializeSteps

func (cs Steps) InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context

InitializeSteps initializes all the steps.

Jump to

Keyboard shortcuts

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