mock

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Password = "password"

Mock server password

View Source
const User = "user"

Mock server user name

Variables

This section is empty.

Functions

func UnmarshalSoapAction

func UnmarshalSoapAction(w http.ResponseWriter, req *http.Request) (string, error)

UnmarshalSoapAction unmarshals a SOAP body from the given HTTP request and determines the contained action.

In case of an error, the corresponding response status code is automatically written.

func WriteSoapResponse

func WriteSoapResponse(w http.ResponseWriter, out any) error

WriteSoapResponse writes a SOAP response by wrapping the given output object into the necessary SOAP envelope.

In case of an error, the corresponding response status code is automatically written.

Types

type ServiceMock

type ServiceMock struct {
	// Path sets the URL path used to invoke this service.
	Path string
	// HandleFunc provides the actual mock functionality (which is called as
	// soon the URL path defined is accessed).
	HandleFunc func(http.ResponseWriter, *http.Request)
}

ServiceMock is used to plugin service mocks.

func ServiceMockFromFile added in v0.1.2

func ServiceMockFromFile(path string, file string) *ServiceMock

ServiceMockFromFile creates a ServiceMock instance sending the given file everytime the associated path is accessed.

type TR064Server

type TR064Server interface {
	// Server gets the HTTP URL the mock server is listenting on.
	Server() *url.URL
	// Server gets the HTTPS URL the mock server is listenting on.
	SecureServer() *url.URL
	// Ping checks whether the mock server is up and running (on the HTTP address).
	Ping() error
	// Ping checks whether the mock server is up and running (on the HTTPS address).
	SecurePing() error
	// Shutdown terminates the mock server gracefully.
	Shutdown()
}

TR064Server interface is used to interact with a mock server instantiated via Start.

func Start

func Start(docsDir string, mocks ...*ServiceMock) TR064Server

Start setup and starts a new mock server.

The mock server establishes a HTTP as well as a HTTPS listener using dynamic ports. Use [Server] and [SecureServer] to get the actual addresses.

Jump to

Keyboard shortcuts

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