testing

package
v0.0.0-...-9ec3720 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCanStopWhenSending

func AssertCanStopWhenSending(c *gc.C, stopper Stopper)

AssertCanStopWhenSending ensures even when there are changes pending to be delivered by the watcher it can still stop cleanly. This is necessary to check for deadlocks in case the watcher's inner loop is blocked trying to send and its tomb is already dying.

func AssertKillAndWait

func AssertKillAndWait(c *gc.C, killWaiter KillWaiter)

func AssertStop

func AssertStop(c *gc.C, stopper Stopper)

func CloudCredential

func CloudCredential(authType cloud.AuthType, attrs map[string]string) state.Credential

CloudCredential is a convenience method to create state.Credential to be used in unit tests.

func Initialize

func Initialize(c *gc.C, owner names.UserTag, cfg *config.Config, controllerInheritedConfig map[string]interface{}, regionConfig cloud.RegionConfig, newPolicy state.NewPolicyFunc) *state.Controller

Initialize initializes the state and returns it. If state was not already initialized, and cfg is nil, the minimal default model configuration will be used. This provides for tests still using a real clock from utils as tests are migrated to use the testing clock

func InitializeWithArgs

func InitializeWithArgs(c *gc.C, args InitializeArgs) *state.Controller

InitializeWithArgs initializes the state and returns it. If state was not already initialized, and args.Config is nil, the minimal default model configuration will be used.

func NewEmptyCredential

func NewEmptyCredential() state.Credential

NewEmptyCredential is a convenience method to create an empty state.Credential with a cloud.EmptyAuthType as auth type to be used in unit tests.

func NewMongoInfo

func NewMongoInfo() *mongo.MongoInfo

NewMongoInfo returns information suitable for connecting to the testing controller's mongo database.

func SetAgentVersion

func SetAgentVersion(st *state.State, vers version.Number) error

SetAgentVersion sets the current agent version in the state's model configuration. This is similar to state.SetModelAgentVersion but it doesn't require that the model have all agents at the same version already.

Types

type InitializeArgs

type InitializeArgs struct {
	Owner                     names.UserTag
	AdminPassword             string
	InitialConfig             *config.Config
	ControllerConfig          map[string]interface{}
	ControllerInheritedConfig map[string]interface{}
	RegionConfig              cloud.RegionConfig
	NewPolicy                 state.NewPolicyFunc
	Clock                     clock.Clock
}

type KillWaiter

type KillWaiter interface {
	Kill()
	Wait() error
}

type MockConfigSchemaSource

type MockConfigSchemaSource struct {
	CloudName string
}

func (*MockConfigSchemaSource) ConfigDefaults

func (m *MockConfigSchemaSource) ConfigDefaults() schema.Defaults

func (*MockConfigSchemaSource) ConfigSchema

func (m *MockConfigSchemaSource) ConfigSchema() schema.Fields

type MockNotifyWatcher

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

MockNotifyWatcher implements state.NotifyWatcher.

func NewMockNotifyWatcher

func NewMockNotifyWatcher(ch <-chan struct{}) *MockNotifyWatcher

func (*MockNotifyWatcher) Changes

func (w *MockNotifyWatcher) Changes() <-chan struct{}

func (*MockNotifyWatcher) Err

func (w *MockNotifyWatcher) Err() error

func (*MockNotifyWatcher) Kill

func (w *MockNotifyWatcher) Kill()

func (*MockNotifyWatcher) Stop

func (w *MockNotifyWatcher) Stop() error

func (*MockNotifyWatcher) Wait

func (w *MockNotifyWatcher) Wait() error

type MockPolicy

type MockPolicy struct {
	GetPrechecker                 func() (environs.InstancePrechecker, error)
	GetConfigValidator            func() (config.Validator, error)
	GetProviderConfigSchemaSource func(cloudName string) (config.ConfigSchemaSource, error)
	GetConstraintsValidator       func() (constraints.Validator, error)
	GetInstanceDistributor        func() (context.Distributor, error)
	GetStorageProviderRegistry    func() (storage.ProviderRegistry, error)
}

func (*MockPolicy) ConfigValidator

func (p *MockPolicy) ConfigValidator() (config.Validator, error)

func (*MockPolicy) ConstraintsValidator

func (p *MockPolicy) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error)

func (*MockPolicy) InstanceDistributor

func (p *MockPolicy) InstanceDistributor() (context.Distributor, error)

func (*MockPolicy) Prechecker

func (p *MockPolicy) Prechecker() (environs.InstancePrechecker, error)

func (*MockPolicy) ProviderConfigSchemaSource

func (p *MockPolicy) ProviderConfigSchemaSource(cloudName string) (config.ConfigSchemaSource, error)

func (*MockPolicy) StorageProviderRegistry

func (p *MockPolicy) StorageProviderRegistry() (storage.ProviderRegistry, error)

type MockStringsWatcher

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

MockStringsWatcher implements state.StringsWatcher.

func NewMockStringsWatcher

func NewMockStringsWatcher(ch <-chan []string) *MockStringsWatcher

func (*MockStringsWatcher) Changes

func (w *MockStringsWatcher) Changes() <-chan []string

func (*MockStringsWatcher) Err

func (w *MockStringsWatcher) Err() error

func (*MockStringsWatcher) Kill

func (w *MockStringsWatcher) Kill()

func (*MockStringsWatcher) Stop

func (w *MockStringsWatcher) Stop() error

func (*MockStringsWatcher) Wait

func (w *MockStringsWatcher) Wait() error

type NotifyWatcher

type NotifyWatcher interface {
	Stop() error
	Changes() <-chan struct{}
}

type NotifyWatcherC

type NotifyWatcherC struct {
	*gc.C
	State   SyncStarter
	Watcher NotifyWatcher
}

NotifyWatcherC embeds a gocheck.C and adds methods to help verify the behaviour of any watcher that uses a <-chan struct{}.

func NewNotifyWatcherC

func NewNotifyWatcherC(c *gc.C, st SyncStarter, w NotifyWatcher) NotifyWatcherC

NewNotifyWatcherC returns a NotifyWatcherC that checks for aggressive event coalescence.

func (NotifyWatcherC) AssertClosed

func (c NotifyWatcherC) AssertClosed()

func (NotifyWatcherC) AssertNoChange

func (c NotifyWatcherC) AssertNoChange()

func (NotifyWatcherC) AssertOneChange

func (c NotifyWatcherC) AssertOneChange()

type RelationUnitsWatcher

type RelationUnitsWatcher interface {
	Stop() error
	Changes() watcher.RelationUnitsChannel
}

type RelationUnitsWatcherC

type RelationUnitsWatcherC struct {
	*gc.C
	State   SyncStarter
	Watcher RelationUnitsWatcher
	// contains filtered or unexported fields
}

RelationUnitsWatcherC embeds a gocheck.C and adds methods to help verify the behaviour of any watcher that uses a <-chan params.RelationUnitsChange.

func NewRelationUnitsWatcherC

func NewRelationUnitsWatcherC(c *gc.C, st SyncStarter, w RelationUnitsWatcher) RelationUnitsWatcherC

NewRelationUnitsWatcherC returns a RelationUnitsWatcherC that checks for aggressive event coalescence.

func (RelationUnitsWatcherC) AssertChange

func (c RelationUnitsWatcherC) AssertChange(changed []string, appChanged []string, departed []string)

AssertChange asserts the given changes was reported by the watcher, but does not assume there are no following changes.

func (RelationUnitsWatcherC) AssertClosed

func (c RelationUnitsWatcherC) AssertClosed()

func (RelationUnitsWatcherC) AssertNoChange

func (c RelationUnitsWatcherC) AssertNoChange()

type StateSuite

type StateSuite struct {
	jujutesting.MgoSuite
	testing.BaseSuite
	NewPolicy                 state.NewPolicyFunc
	Controller                *state.Controller
	StatePool                 *state.StatePool
	State                     *state.State
	Model                     *state.Model
	Owner                     names.UserTag
	AdminPassword             string
	Factory                   *factory.Factory
	InitialConfig             *config.Config
	InitialTime               time.Time
	ControllerConfig          map[string]interface{}
	ControllerInheritedConfig map[string]interface{}
	RegionConfig              cloud.RegionConfig
	Clock                     *testclock.Clock
	// contains filtered or unexported fields
}

StateSuite provides setup and teardown for tests that require a state.State.

func (*StateSuite) SetUpSuite

func (s *StateSuite) SetUpSuite(c *gc.C)

func (*StateSuite) SetUpTest

func (s *StateSuite) SetUpTest(c *gc.C)

func (*StateSuite) TearDownSuite

func (s *StateSuite) TearDownSuite(c *gc.C)

func (*StateSuite) TearDownTest

func (s *StateSuite) TearDownTest(c *gc.C)

func (*StateSuite) WaitForModelWatchersIdle

func (s *StateSuite) WaitForModelWatchersIdle(c *gc.C, modelUUID string)

WaitForModelWatchersIdle firstly waits for the txn poller to process all pending changes, then waits for the hub watcher on the state object to have finished processing all those events.

func (*StateSuite) WaitForNextSync

func (s *StateSuite) WaitForNextSync(c *gc.C)

WaitForNextSync repeatedly advances the testing clock with short waits between until the txn poller doesn't find any more changes.

type StateWithWallClockSuite

type StateWithWallClockSuite struct {
	testing.MgoSuite
	coretesting.BaseSuite
	NewPolicy                 state.NewPolicyFunc
	Controller                *state.Controller
	StatePool                 *state.StatePool
	State                     *state.State
	Model                     *state.Model
	Owner                     names.UserTag
	Factory                   *factory.Factory
	InitialConfig             *config.Config
	ControllerInheritedConfig map[string]interface{}
	RegionConfig              cloud.RegionConfig
}

StateWithWallClockSuite provides setup and teardown for tests that require a state.State. This should be deprecated in favour of StateSuite, and tests updated to use the testing clock StateSuite provides.

func (*StateWithWallClockSuite) SetUpSuite

func (s *StateWithWallClockSuite) SetUpSuite(c *gc.C)

func (*StateWithWallClockSuite) SetUpTest

func (s *StateWithWallClockSuite) SetUpTest(c *gc.C)

func (*StateWithWallClockSuite) TearDownSuite

func (s *StateWithWallClockSuite) TearDownSuite(c *gc.C)

func (*StateWithWallClockSuite) TearDownTest

func (s *StateWithWallClockSuite) TearDownTest(c *gc.C)

type Stopper

type Stopper interface {
	Stop() error
}

type StringsWatcher

type StringsWatcher interface {
	Stop() error
	Changes() <-chan []string
}

type StringsWatcherC

type StringsWatcherC struct {
	*gc.C
	State   SyncStarter
	Watcher StringsWatcher
}

StringsWatcherC embeds a gocheck.C and adds methods to help verify the behaviour of any watcher that uses a <-chan []string.

func NewStringsWatcherC

func NewStringsWatcherC(c *gc.C, st SyncStarter, w StringsWatcher) StringsWatcherC

NewStringsWatcherC returns a StringsWatcherC that checks for aggressive event coalescence.

func (StringsWatcherC) AssertChange

func (c StringsWatcherC) AssertChange(expect ...string)

func (StringsWatcherC) AssertChangeInSingleEvent

func (c StringsWatcherC) AssertChangeInSingleEvent(expect ...string)

func (StringsWatcherC) AssertChangeMaybeIncluding

func (c StringsWatcherC) AssertChangeMaybeIncluding(expect ...string)

AssertChangeMaybeIncluding verifies that there is a change that may contain zero to all of the passed in strings, and no other changes.

func (StringsWatcherC) AssertChanges

func (c StringsWatcherC) AssertChanges()

func (StringsWatcherC) AssertClosed

func (c StringsWatcherC) AssertClosed()

func (StringsWatcherC) AssertNoChange

func (c StringsWatcherC) AssertNoChange()

type SyncStarter

type SyncStarter interface {
	StartSync()
}

SyncStarter is an interface that watcher checkers will use to ensure that changes to the watched object have been synchronized. This is primarily implemented by state.State.

Jump to

Keyboard shortcuts

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