testing

package
v0.0.0-...-84dfa8d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: AGPL-3.0 Imports: 85 Imported by: 60

Documentation

Index

Constants

View Source
const AdminSecret = "dummy-secret"

Variables

View Source
var (
	// AdminUser is the default admin user for a controller.
	AdminUser = names.NewUserTag("admin")
	AdminName = coreuser.NameFromTag(AdminUser)

	// DefaultCloudRegion is the default cloud region for a controller model.
	DefaultCloudRegion = "dummy-region"

	// DefaultCloud is the default cloud for a controller model.
	DefaultCloud = cloud.Cloud{
		Name:      "dummy",
		Type:      "dummy",
		AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.AccessKeyAuthType, cloud.UserPassAuthType},
		Regions:   []cloud.Region{{Name: DefaultCloudRegion}},
	}

	// DefaultCredentialTag is the default credential for all models.
	DefaultCredentialTag = names.NewCloudCredentialTag("dummy/admin/default")

	// DefaultCredentialId is the default credential id for all models.
	DefaultCredentialId = corecredential.KeyFromTag(DefaultCredentialTag)
)

Functions

func AddControllerMachine

func AddControllerMachine(
	c *gc.C,
	st *state.State,
	controllerConfig controller.Config,
) *state.Machine

AddControllerMachine adds a "controller" machine to the state so that State.Addresses and State.APIAddresses will work. It returns the added machine. The addresses that those methods will return bear no relation to the addresses actually used by the state and API servers. It returns the addresses that will be returned by the State.Addresses and State.APIAddresses methods, which will not bear any relation to the be the addresses used by the controllers.

func AssertStartControllerInstance

func AssertStartControllerInstance(
	c *gc.C, env environs.Environ, ctx envcontext.ProviderCallContext, controllerUUID, machineId string,
) (
	instances.Instance, *instance.HardwareCharacteristics,
)

AssertStartControllerInstance is a test helper function that starts a controller instance with a plausible but invalid configuration, and checks that it succeeds.

func AssertStartInstance

func AssertStartInstance(
	c *gc.C, env environs.Environ, ctx envcontext.ProviderCallContext, controllerUUID, machineId string,
) (
	instances.Instance, *instance.HardwareCharacteristics,
)

AssertStartInstance is a test helper function that starts an instance with a plausible but invalid configuration, and checks that it succeeds.

func AssertStartInstanceWithConstraints

func AssertStartInstanceWithConstraints(
	c *gc.C, env environs.Environ, ctx envcontext.ProviderCallContext,
	controllerUUID, machineId string, cons constraints.Value,
) (
	instances.Instance, *instance.HardwareCharacteristics,
)

AssertStartInstanceWithConstraints is a test helper function that starts an instance with the given constraints, and a plausible but invalid configuration, and returns the result of Environ.StartInstance.

func DefaultServerConfig

func DefaultServerConfig(c *gc.C, testclock clock.Clock) apiserver.ServerConfig

DefaultServerConfig returns a minimal server config.

func FakeAPIInfo

func FakeAPIInfo(machineId string) *api.Info

FakeAPIInfo holds information about no state - it will always give an error when connected to. The machine id gives the machine id of the machine to be started.

func FillInStartInstanceParams

func FillInStartInstanceParams(env environs.Environ, machineId string, isController bool, params *environs.StartInstanceParams) error

FillInStartInstanceParams prepares the instance parameters for starting the instance.

func InsertDummyCloudType

func InsertDummyCloudType(ctx context.Context, controller, model database.TxnRunner) error

InsertDummyCloudType is a db bootstrap option which inserts the dummy cloud type.

func MacaroonEquals

func MacaroonEquals(c *gc.C, m1, m2 *macaroon.Macaroon)

func MacaroonsEqual

func MacaroonsEqual(c *gc.C, ms1, ms2 []macaroon.Slice) error

func MustNewMacaroon

func MustNewMacaroon(id string) *macaroon.Macaroon

func NewMacaroon

func NewMacaroon(id string) (*macaroon.Macaroon, error)

func NewObjectStore

func NewObjectStore(c *gc.C, modelUUID string) coreobjectstore.ObjectStore

NewObjectStore creates a new object store for testing. This uses the memory metadata service.

func NewObjectStoreWithMetadataService

func NewObjectStoreWithMetadataService(c *gc.C, modelUUID string, metadataService objectstore.MetadataService) coreobjectstore.ObjectStore

NewObjectStoreWithMetadataService creates a new object store for testing.

func SeedDatabase

func SeedDatabase(c *gc.C, controller database.TxnRunner, domainServices services.DomainServices, controllerConfig controller.Config)

SeedDatabase the database with a supplied controller config, and dummy cloud and dummy credentials.

func SetImageMetadata

func SetImageMetadata(env environs.Environ, fetcher imagemetadata.SimplestreamsFetcher, release, arches []string, out *[]*imagemetadata.ImageMetadata) error

func StartInstance

StartInstance is a test helper function that starts an instance with a plausible but invalid configuration, and returns the result of Environ.StartInstance.

func StartInstanceWithConstraints

func StartInstanceWithConstraints(
	env environs.Environ,
	ctx envcontext.ProviderCallContext,
	controllerUUID, machineId string, cons constraints.Value,
) (
	instances.Instance, *instance.HardwareCharacteristics, corenetwork.InterfaceInfos, error,
)

StartInstanceWithConstraints is a test helper function that starts an instance with the given constraints, and a plausible but invalid configuration, and returns the result of Environ.StartInstance.

func StartInstanceWithParams

func StartInstanceWithParams(
	env environs.Environ, ctx envcontext.ProviderCallContext,
	machineId string,
	params environs.StartInstanceParams,
) (
	*environs.StartInstanceResult, error,
)

StartInstanceWithParams is a test helper function that starts an instance with the given parameters, and a plausible but invalid configuration, and returns the result of Environ.StartInstance. The provided params's InstanceConfig and Tools field values will be ignored.

func WaitInstanceAddresses

func WaitInstanceAddresses(
	env environs.Environ, ctx envcontext.ProviderCallContext, instId instance.Id,
) (corenetwork.ProviderAddresses, error)

WaitInstanceAddresses waits until the specified instance has addresses, and returns them.

Types

type ApiServerSuite

type ApiServerSuite struct {
	servicefactorytesting.DomainServicesSuite

	// MgoSuite is needed until we finally can
	// represent the model fully in dqlite.
	mgotesting.MgoSuite

	// ControllerConfigAttrs can be set up before SetUpTest
	// is invoked. Any attributes set here will be added to
	// the suite's controller configuration.
	ControllerConfigAttrs map[string]interface{}

	// ControllerModelConfigAttrs can be set up before SetUpTest
	// is invoked. Any attributes set here will be added to
	// the suite's controller model configuration.
	ControllerModelConfigAttrs map[string]interface{}

	// These are exposed for the tests to use.
	Server            *apiserver.Server
	LeaseManager      *lease.Manager
	ObjectStoreGetter objectstore.ObjectStoreGetter
	Clock             testclock.AdvanceableClock

	WithLeaseManager        bool
	WithControllerModelType state.ModelType
	WithEmbeddedCLICommand  func(ctx *cmd.Context, store jujuclient.ClientStore, whitelist []string, cmdPlusArgs string) int

	WithUpgrading      bool
	WithAuditLogConfig *auditlog.Config
	WithIntrospection  func(func(string, http.Handler))

	// AdminUserUUID is the root user for the controller.
	AdminUserUUID coreuser.UUID

	// ControllerUUID is the unique identifier for the controller.
	ControllerUUID string

	// InstancePrechecker is used to validate instance creation.
	//
	// Deprecated: This will be removed in the future.
	InstancePrechecker func(*gc.C, *state.State) environs.InstancePrechecker
	// contains filtered or unexported fields
}

ApiServerSuite is a text fixture which spins up an apiserver on top of a controller model.

func (*ApiServerSuite) ControllerModel

func (s *ApiServerSuite) ControllerModel(c *gc.C) *state.Model

ControllerModel returns the controller model.

func (*ApiServerSuite) ControllerModelApiInfo

func (s *ApiServerSuite) ControllerModelApiInfo() *api.Info

ControllerModelApiInfo returns the api address and ca cert needed to connect to an api server's controller model endpoint. User and password are empty.

func (*ApiServerSuite) ControllerModelUUID

func (s *ApiServerSuite) ControllerModelUUID() string

ControllerModelUUID returns the controller model uuid.

func (*ApiServerSuite) Model

func (s *ApiServerSuite) Model(c *gc.C, uuid string) (*state.Model, func() bool)

Model returns the specified model.

func (*ApiServerSuite) ModelApiInfo

func (s *ApiServerSuite) ModelApiInfo(modelUUID string) *api.Info

ModelApiInfo returns the api address and ca cert needed to connect to an api server's model endpoint. User and password are empty.

func (*ApiServerSuite) NewFactory

func (s *ApiServerSuite) NewFactory(c *gc.C, modelUUID string) (*factory.Factory, func() bool)

NewFactory returns a factory for the given model.

func (*ApiServerSuite) ObjectStore

func (s *ApiServerSuite) ObjectStore(c *gc.C, uuid string) objectstore.ObjectStore

ObjectStore returns the object store for the given model uuid.

func (*ApiServerSuite) OpenAPIAsNewMachine

func (s *ApiServerSuite) OpenAPIAsNewMachine(c *gc.C, jobs ...state.MachineJob) (api.Connection, *state.Machine)

OpenAPIAsNewMachine creates a new machine entry that lives in system state, and then uses that to open the API. The returned api.Connection should not be closed by the caller as a cleanup function has been registered to do that. The machine will run the supplied jobs; if none are given, JobHostUnits is assumed.

func (*ApiServerSuite) OpenControllerAPI

func (s *ApiServerSuite) OpenControllerAPI(c *gc.C) api.Connection

OpenControllerAPI opens a controller api connection for the admin user.

func (*ApiServerSuite) OpenControllerAPIAs

func (s *ApiServerSuite) OpenControllerAPIAs(c *gc.C, tag names.Tag, password string) api.Connection

OpenControllerAPIAs opens a controller api connection.

func (*ApiServerSuite) OpenControllerModelAPI

func (s *ApiServerSuite) OpenControllerModelAPI(c *gc.C) api.Connection

OpenControllerModelAPI opens the controller model api connection for the admin user.

func (*ApiServerSuite) OpenModelAPI

func (s *ApiServerSuite) OpenModelAPI(c *gc.C, modelUUID string) api.Connection

OpenModelAPI opens a model api connection for the admin user.

func (*ApiServerSuite) OpenModelAPIAs

func (s *ApiServerSuite) OpenModelAPIAs(c *gc.C, modelUUID string, tag names.Tag, password, nonce string) api.Connection

OpenModelAPIAs opens a model api connection.

func (*ApiServerSuite) SeedCAASCloud

func (s *ApiServerSuite) SeedCAASCloud(c *gc.C)

func (*ApiServerSuite) SetUpSuite

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

func (*ApiServerSuite) SetUpTest

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

func (*ApiServerSuite) StatePool

func (s *ApiServerSuite) StatePool() *state.StatePool

StatePool returns the server's state pool.

func (*ApiServerSuite) TearDownTest

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

func (*ApiServerSuite) URL

func (s *ApiServerSuite) URL(path string, queryParams url.Values) *url.URL

URL returns a URL for this server with the given path and query parameters. The URL scheme will be "https".

type ClearableCookieJar

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

ClearableCookieJar implements a cookie jar that can be cleared of all cookies for testing purposes.

func NewClearableCookieJar

func NewClearableCookieJar() *ClearableCookieJar

NewClearableCookieJar returns a new ClearableCookieJar.

func (*ClearableCookieJar) Clear

func (jar *ClearableCookieJar) Clear()

Clear clears all the cookies in the jar. It is not OK to call Clear concurrently with the other methods.

func (*ClearableCookieJar) Cookies

func (jar *ClearableCookieJar) Cookies(u *url.URL) []*http.Cookie

Cookies implements http.CookieJar.Cookies.

func (*ClearableCookieJar) SetCookies

func (jar *ClearableCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements http.CookieJar.SetCookies.

type MacaroonSuite

type MacaroonSuite struct {
	ApiServerSuite

	// DischargerLogin is called by the discharger when an
	// API macaroon is discharged. It should either return
	// the chosen username or an empty string, in which case
	// the discharge is denied.
	// If this is nil, func() {return ""} is implied.
	DischargerLogin func() string
	// contains filtered or unexported fields
}

MacaroonSuite wraps a ApiServerSuite with macaroon authentication enabled.

func (*MacaroonSuite) APIInfo

func (s *MacaroonSuite) APIInfo(c *gc.C) *api.Info

APIInfo returns API connection info suitable for connecting to the API using macaroon authentication.

func (*MacaroonSuite) AddControllerUser

func (s *MacaroonSuite) AddControllerUser(c *gc.C, username user.Name, accessLevel permission.Access)

AddControllerUser is a convenience function that adds a controller user with the specified access.

func (*MacaroonSuite) AddModelUser

func (s *MacaroonSuite) AddModelUser(c *gc.C, username user.Name)

AddModelUser is a convenience function that adds an external user to the current model. It will panic if the user is local.

func (*MacaroonSuite) DischargerLocation

func (s *MacaroonSuite) DischargerLocation() string

DischargerLocation returns the URL of the third party caveat discharger.

func (*MacaroonSuite) OpenAPI

func (s *MacaroonSuite) OpenAPI(c *gc.C, info *api.Info, jar http.CookieJar) api.Connection

OpenAPI opens a connection to the API using the given information. and empty DialOpts. If info is nil, s.APIInfo(c) is used. If jar is non-nil, it will be used as the store for the cookies created as a result of API interaction.

func (*MacaroonSuite) SetUpTest

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

func (*MacaroonSuite) TearDownTest

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

Jump to

Keyboard shortcuts

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