harness

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

package harness contains functionality for setting up and testing the coordinator in various different states. This includes full integration tests and smaller unit tests

Index

Constants

View Source
const AdminEmail = models.Email("admin@cape.com")
View Source
const AdminName = models.Name("admin")
View Source
const AdminPassword = "iamtheadmin"

Variables

View Source
var (
	TimeoutCause    = errors.NewCause(errors.RequestTimeoutCategory, "start_timeout")
	NotStartedCause = errors.NewCause(errors.BadRequestCategory, "coordinator_not_started")
)
View Source
var (
	MissingConfig = errors.NewCause(errors.BadRequestCategory, "missing_config")
)

Functions

func TestLogger added in v0.0.2

func TestLogger() *zerolog.Logger

TestLogger returns a logger for use in writing tests

Types

type Config

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

Config represents the configuration required to create a Coordinator Harness

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns an instantiated version of the Coordinator Harness configuration

func (*Config) Migrations

func (c *Config) Migrations() []string

Migrations returns a list of directories containing migrations

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the struct contains invalid configuration

type Harness

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

Harness represents a http server used for testing. Its responsibility is to provide the transport layer for the application contained within the component. In this case, the component represents a Coordinator.

This is a convenience layer for testing the Coordinator by spinning up a database, migrating it, running the tests, tearing them down, and then cleaning any remaining artifacts up.

This harness uses net/http/httptest.Server so it will start the server on a randomized port that has not yet been assigned.

This harness _does not_ manage any client state or actually "setup" the coordinator admin functionality. Please see the harness.Manager which provides convenience functions for managing application state.

You can use it as follows:

h, err := NewHarness(cfg)
if err != nil {
  return err // Handle your errors!
}
err = h.Setup(ctx)
...
defer h.Teardown()

func NewHarness

func NewHarness(cfg *Config) (*Harness, error)

NewHarness returns a new harness that's configured and ready to be setup!

func (*Harness) Client

func (h *Harness) Client() (*coordinator.Client, error)

Client returns an unauthenticated Client for the underlying instance of the coordinator.

func (*Harness) Mails

func (h *Harness) Mails() []*mailer.TestMail

Mails returns a list of emails sent by this server instance

func (*Harness) Manager

func (h *Harness) Manager() *Manager

Manager returns a test state manager for this Harness

func (*Harness) Setup

func (h *Harness) Setup(ctx context.Context) error

Setup sets up the testing harness to test the Coordinator component

func (*Harness) Teardown

func (h *Harness) Teardown() error

Teardown destroys all of the underlying resources needed by the Coordinator and stops the test server from serving it at all!

func (*Harness) URL

func (h *Harness) URL() (*models.URL, error)

URL returns the url to the running coordinator once the harness has been started.

type Manager

type Manager struct {
	Admin *User
	// contains filtered or unexported fields
}

Manager represents an application state manager on-top of the Coordinator's harness. It's job is to provide convenience functions for setting up a coordinator's application state, managing users, and other utilities that make it write end-to-end integration tests.

func (*Manager) Setup

func (m *Manager) Setup(ctx context.Context) (*coordinator.Client, error)

Setup sets up the application state for the cluster (e.g. the `setup` mutation for the coordinator). This results in the creation of an Admin user.

An authenticated client for the admin is returned.

func (*Manager) URL

func (m *Manager) URL() (*models.URL, error)

URL returns the url of the coordinator

type User

type User struct {
	Client   *coordinator.Client
	User     models.User
	Password models.Password
	Token    *base64.Value
}

User represents a user in the cape coordinator

Jump to

Keyboard shortcuts

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