Documentation ¶
Overview ¶
Package storagetest provides utilities to assist in testing caddytls.Storage implementations.
Index ¶
- func InMemoryStorageCreator(caURL *url.URL) (caddytls.Storage, error)
- type InMemoryStorage
- func (s *InMemoryStorage) Clear()
- func (s *InMemoryStorage) DeleteSite(domain string) error
- func (s *InMemoryStorage) LoadSite(domain string) (*caddytls.SiteData, error)
- func (s *InMemoryStorage) LoadUser(email string) (*caddytls.UserData, error)
- func (s *InMemoryStorage) MostRecentUserEmail() string
- func (s *InMemoryStorage) SiteExists(domain string) (bool, error)
- func (s *InMemoryStorage) StoreSite(domain string, data *caddytls.SiteData) error
- func (s *InMemoryStorage) StoreUser(email string, data *caddytls.UserData) error
- func (s *InMemoryStorage) TryLock(domain string) (caddytls.Waiter, error)
- func (s *InMemoryStorage) Unlock(domain string) error
- type StorageTest
- func (s *StorageTest) AllFuncs() []TestFunc
- func (s *StorageTest) Test(t *testing.T, eagerFail bool)
- func (s *StorageTest) TestAll(eagerFail bool) (errs []error)
- func (s *StorageTest) TestMostRecentUserEmail() error
- func (s *StorageTest) TestSite() error
- func (s *StorageTest) TestSiteExists() error
- func (s *StorageTest) TestUser() error
- type TestFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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.