testkit

package
v0.0.0-...-0a82dba Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPRead

func HTTPRead(url string) (string, error)

Types

type HelloResponse

type HelloResponse struct {
	ServerAddress string
	ServerName    string
	Date          time.Time
	URI           string
	RequestID     string
}

func HelloNginx

func HelloNginx(addr string, port uint16) (*HelloResponse, error)

type MockAPIServer

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

MockAPIServer is a mock http server that builds on httptest.Server and http.ServeMux and provides methods to easily return mocked cloudscale API responses.

func NewMockAPIServer

func NewMockAPIServer() *MockAPIServer

func (*MockAPIServer) Client

func (m *MockAPIServer) Client() *cloudscale.Client

Client returns a cloudscale client pointing at the mock API server.

func (*MockAPIServer) Close

func (m *MockAPIServer) Close()

Close stops/closes the server and resets it.

func (*MockAPIServer) LastSent

func (m *MockAPIServer) LastSent(v any)

LastSent unmarshals the JSON last sent to the API server via POST/PUT/PATCH.

func (*MockAPIServer) On

func (m *MockAPIServer) On(pattern string, status int, data any)

On matches the given pattern and returns a status and the given data. The data can be a string or anything that go can marshal into a JSON.

The servrer adds a default route that respods with an empty JSON object and a 404 status code.

Note, this method has no effect if the server is started, and all registered patterns need to be re-applied after the server is stopped using Close.

func (*MockAPIServer) Start

func (m *MockAPIServer) Start()

Start runs the server in the background, until it is stopped/closed.

func (*MockAPIServer) WithLoadBalancers

func (m *MockAPIServer) WithLoadBalancers(lbs []cloudscale.LoadBalancer)

WithLoadBalancers ensures that the /v1/loadbalancers endpoints respond with the given loadbalancer objects. In addition to /v1/loadbalancers, this also implements /v1/loadbalancers/<uuid> for any loadbalancer with a UUID.

func (*MockAPIServer) WithServers

func (m *MockAPIServer) WithServers(servers []cloudscale.Server)

WithServers ensures that the /v1/servers endpoints respond with the given server objects. In addition to /v1/servers, this also implements /v1/servers/<uuid> for any server with a UUID.

type Node

type Node struct {
	Name       string
	ProviderID string
}

Node helps construct Kubernetes v1.Node objects for testing

func NewNode

func NewNode(name string) *Node

func (*Node) V1

func (n *Node) V1() *v1.Node

func (*Node) WithName

func (n *Node) WithName(name string) *Node

func (*Node) WithProviderID

func (n *Node) WithProviderID(id string) *Node

type Service

type Service struct {
	Name string
}

Service helps construct Kubernetes v1.Service objects for testing

func NewService

func NewService(name string) *Service

func (*Service) V1

func (s *Service) V1() *v1.Service

func (*Service) WithName

func (s *Service) WithName(name string) *Service

Jump to

Keyboard shortcuts

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