storagetest

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package storagetest provides utilities to assist in testing caddytls.Storage implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InMemoryStorageCreator

func InMemoryStorageCreator(caURL *url.URL) (caddytls.Storage, error)

InMemoryStorageCreator is a caddytls.Storage.StorageCreator to create InMemoryStorage instances for testing.

Types

type InMemoryStorage

type InMemoryStorage struct {
	// Sites are exposed for testing purposes.
	Sites map[string]*caddytls.SiteData
	// Users are exposed for testing purposes.
	Users map[string]*caddytls.UserData
	// LastUserEmail is exposed for testing purposes.
	LastUserEmail string
}

InMemoryStorage is a caddytls.Storage implementation for use in testing. It simply stores information in runtime memory.

func NewInMemoryStorage

func NewInMemoryStorage() *InMemoryStorage

NewInMemoryStorage constructs an InMemoryStorage instance. For use with caddytls, the InMemoryStorageCreator should be used instead.

func (*InMemoryStorage) Clear

func (s *InMemoryStorage) Clear()

Clear completely clears all values associated with this storage.

func (*InMemoryStorage) DeleteSite

func (s *InMemoryStorage) DeleteSite(domain string) error

DeleteSite implements caddytls.Storage.DeleteSite in memory.

func (*InMemoryStorage) LoadSite

func (s *InMemoryStorage) LoadSite(domain string) (*caddytls.SiteData, error)

LoadSite implements caddytls.Storage.LoadSite in memory.

func (*InMemoryStorage) LoadUser

func (s *InMemoryStorage) LoadUser(email string) (*caddytls.UserData, error)

LoadUser implements caddytls.Storage.LoadUser in memory.

func (*InMemoryStorage) MostRecentUserEmail

func (s *InMemoryStorage) MostRecentUserEmail() string

MostRecentUserEmail implements caddytls.Storage.MostRecentUserEmail in memory.

func (*InMemoryStorage) SiteExists

func (s *InMemoryStorage) SiteExists(domain string) (bool, error)

SiteExists implements caddytls.Storage.SiteExists in memory.

func (*InMemoryStorage) StoreSite

func (s *InMemoryStorage) StoreSite(domain string, data *caddytls.SiteData) error

StoreSite implements caddytls.Storage.StoreSite in memory.

func (*InMemoryStorage) StoreUser

func (s *InMemoryStorage) StoreUser(email string, data *caddytls.UserData) error

StoreUser implements caddytls.Storage.StoreUser in memory.

func (*InMemoryStorage) TryLock added in v0.9.2

func (s *InMemoryStorage) TryLock(domain string) (caddytls.Waiter, error)

TryLock implements Storage.TryLock by returning nil values because it is not a multi-server storage implementation.

func (*InMemoryStorage) Unlock added in v0.9.2

func (s *InMemoryStorage) Unlock(domain string) error

Unlock implements Storage.Unlock as a no-op because it is not a multi-server storage implementation.

type StorageTest

type StorageTest struct {
	// Storage is the implementation to use during tests. This must be
	// present.
	caddytls.Storage

	// PreTest, if present, is called before every test. Any error returned
	// is returned from the test and the test does not continue.
	PreTest func() error

	// PostTest, if present, is executed after every test via defer which
	// means it executes even on failure of the test (but not on failure of
	// PreTest).
	PostTest func()

	// AfterUserEmailStore, if present, is invoked during
	// TestMostRecentUserEmail after each storage just in case anything
	// needs to be mocked.
	AfterUserEmailStore func(email string) error
}

StorageTest is a test harness that contains tests to execute all exposed parts of a Storage implementation.

func (*StorageTest) AllFuncs

func (s *StorageTest) AllFuncs() []TestFunc

AllFuncs returns all test functions that are part of this harness.

func (*StorageTest) Test

func (s *StorageTest) Test(t *testing.T, eagerFail bool)

Test executes the entire harness using the testing package. Failures are reported via T.Fatal. If eagerFail is true, the first failure causes all testing to stop immediately.

func (*StorageTest) TestAll

func (s *StorageTest) TestAll(eagerFail bool) (errs []error)

TestAll executes the entire harness and returns the results as an array of errors. If eagerFail is true, the first failure causes all testing to stop immediately.

func (*StorageTest) TestMostRecentUserEmail

func (s *StorageTest) TestMostRecentUserEmail() error

TestMostRecentUserEmail tests Storage.MostRecentUserEmail.

func (*StorageTest) TestSite

func (s *StorageTest) TestSite() error

TestSite tests Storage.LoadSite, Storage.StoreSite, and Storage.DeleteSite.

func (*StorageTest) TestSiteExists

func (s *StorageTest) TestSiteExists() error

TestSiteExists tests Storage.SiteExists.

func (*StorageTest) TestUser

func (s *StorageTest) TestUser() error

TestUser tests Storage.LoadUser and Storage.StoreUser.

type TestFunc

type TestFunc struct {
	// Name is the friendly name of the test.
	Name string

	// Fn is the function that is invoked for the test.
	Fn func() error
}

TestFunc holds information about a test.

Jump to

Keyboard shortcuts

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