juju: github.com/juju/juju/apiserver/testing Index | Files

package testing

import "github.com/juju/juju/apiserver/testing"

Index

Package Files

errors.go fakeapi.go fakeauditlog.go fakeauthorizer.go fakecharmstore.go fakenotifywatcher.go http.go service.go stub_lease_manager.go stub_network.go stub_pool.go

Constants

const (
    StubProviderType               = "stub-provider"
    StubEnvironName                = "stub-environ"
    StubZonedEnvironName           = "stub-zoned-environ"
    StubNetworkingEnvironName      = "stub-networking-environ"
    StubZonedNetworkingEnvironName = "stub-zoned-networking-environ"
)

Variables

var (
    // SharedStub records all method calls to any of the stubs.
    SharedStub = &testing.Stub{}

    BackingInstance                = &StubBacking{Stub: SharedStub}
    ProviderInstance               = &StubProvider{Stub: SharedStub}
    EnvironInstance                = &StubEnviron{Stub: SharedStub}
    ZonedEnvironInstance           = &StubZonedEnviron{Stub: SharedStub}
    NetworkingEnvironInstance      = &StubNetworkingEnviron{Stub: SharedStub}
    ZonedNetworkingEnvironInstance = &StubZonedNetworkingEnviron{Stub: SharedStub}
)
var ErrUnauthorized = &params.Error{
    Message: "permission denied",
    Code:    params.CodeUnauthorized,
}

func AlreadyExistsError Uses

func AlreadyExistsError(what string) *params.Error

func AssertNotImplemented Uses

func AssertNotImplemented(c *gc.C, apiFacade interface{}, methodName string)

func AssertPrincipalApplicationDeployed Uses

func AssertPrincipalApplicationDeployed(c *gc.C, st *state.State, applicationName string, curl *charm.URL, forced bool, bundle charm.Charm, cons constraints.Value) *state.Application

func AssertResponse Uses

func AssertResponse(c *gc.C, resp *http.Response, expHTTPStatus int, expContentType string) []byte

func CheckMethodCalls Uses

func CheckMethodCalls(c *gc.C, stub *testing.Stub, calls ...StubMethodCall)

CheckMethodCalls works like testing.Stub.CheckCalls, but also checks the receivers.

func NotAssignedError Uses

func NotAssignedError(unitName string) *params.Error

func NotFoundError Uses

func NotFoundError(prefixMessage string) *params.Error

func NotProvisionedError Uses

func NotProvisionedError(machineId string) *params.Error

func PrefixedError Uses

func PrefixedError(prefix, message string) *params.Error

func ResetStub Uses

func ResetStub(stub *testing.Stub)

ResetStub resets all recorded calls and errors of the given stub.

func SendHTTPRequest Uses

func SendHTTPRequest(c *gc.C, p HTTPRequestParams) *http.Response

func ServerError Uses

func ServerError(message string) *params.Error

type CharmStoreSuite Uses

type CharmStoreSuite struct {
    testing.CleanupSuite

    Session *mgo.Session
    // DischargeUser holds the identity of the user
    // that the 3rd party caveat discharger will issue
    // macaroons for. If it is empty, no caveats will be discharged.
    DischargeUser string

    Srv    *httptest.Server
    Client *csclient.Client
    // contains filtered or unexported fields
}

func (*CharmStoreSuite) SetUpTest Uses

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

func (*CharmStoreSuite) TearDownTest Uses

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

func (*CharmStoreSuite) UploadCharm Uses

func (s *CharmStoreSuite) UploadCharm(c *gc.C, url, name string) (*charm.URL, charm.Charm)

func (*CharmStoreSuite) UploadCharmMultiSeries Uses

func (s *CharmStoreSuite) UploadCharmMultiSeries(c *gc.C, url, name string) (*charm.URL, charm.Charm)

func (*CharmStoreSuite) UploadCharmWithSeries Uses

func (s *CharmStoreSuite) UploadCharmWithSeries(c *gc.C, url, name, series string) (*charm.URL, charm.Charm)

type FakeAuditLog Uses

type FakeAuditLog struct {
    testing.Stub
}

FakeAuditLog implements auditlog.AuditLog.

func (*FakeAuditLog) AddConversation Uses

func (l *FakeAuditLog) AddConversation(m auditlog.Conversation) error

func (*FakeAuditLog) AddRequest Uses

func (l *FakeAuditLog) AddRequest(m auditlog.Request) error

func (*FakeAuditLog) AddResponse Uses

func (l *FakeAuditLog) AddResponse(m auditlog.ResponseErrors) error

func (*FakeAuditLog) Close Uses

func (l *FakeAuditLog) Close() error

type FakeAuthorizer Uses

type FakeAuthorizer struct {
    Tag         names.Tag
    Controller  bool
    ModelUUID   string
    AdminTag    names.UserTag
    HasWriteTag names.UserTag
}

FakeAuthorizer implements the facade.Authorizer interface.

func (FakeAuthorizer) AuthApplicationAgent Uses

func (fa FakeAuthorizer) AuthApplicationAgent() bool

AuthApplicationAgent returns whether the current client is an application operator.

func (FakeAuthorizer) AuthClient Uses

func (fa FakeAuthorizer) AuthClient() bool

AuthClient returns whether the authenticated entity is a client user.

func (FakeAuthorizer) AuthController Uses

func (fa FakeAuthorizer) AuthController() bool

func (FakeAuthorizer) AuthMachineAgent Uses

func (fa FakeAuthorizer) AuthMachineAgent() bool

AuthMachineAgent returns whether the current client is a machine agent.

func (FakeAuthorizer) AuthOwner Uses

func (fa FakeAuthorizer) AuthOwner(tag names.Tag) bool

func (FakeAuthorizer) AuthUnitAgent Uses

func (fa FakeAuthorizer) AuthUnitAgent() bool

AuthUnitAgent returns whether the current client is a unit agent.

func (FakeAuthorizer) ConnectedModel Uses

func (fa FakeAuthorizer) ConnectedModel() string

ConnectedModel returns the UUID of the model the current client is connected to.

func (FakeAuthorizer) GetAuthTag Uses

func (fa FakeAuthorizer) GetAuthTag() names.Tag

func (FakeAuthorizer) HasPermission Uses

func (fa FakeAuthorizer) HasPermission(operation permission.Access, target names.Tag) (bool, error)

HasPermission returns true if the logged in user is admin or has a name equal to the pre-set admin tag.

func (FakeAuthorizer) UserHasPermission Uses

func (fa FakeAuthorizer) UserHasPermission(user names.UserTag, operation permission.Access, target names.Tag) (bool, error)

UserHasPermission returns true if the passed user is admin or has a name equal to the pre-set admin tag.

type FakeNotifyWatcher Uses

type FakeNotifyWatcher struct {
    worker.Worker
    C   chan struct{}
}

FakeNotifyWatcher is an implementation of state.NotifyWatcher which is useful in tests.

func NewFakeNotifyWatcher Uses

func NewFakeNotifyWatcher() *FakeNotifyWatcher

func (*FakeNotifyWatcher) Changes Uses

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

Changes is part of the state.NotifyWatcher interface.

func (*FakeNotifyWatcher) Err Uses

func (w *FakeNotifyWatcher) Err() error

Err is part of the state.NotifyWatcher interface.

func (*FakeNotifyWatcher) Stop Uses

func (w *FakeNotifyWatcher) Stop() error

Stop is part of the state.NotifyWatcher interface.

type FakeSpace Uses

type FakeSpace struct {
    SpaceId   string
    SpaceName string
    SubnetIds []string
    Public    bool
    NextErr   errReturner
}

FakeSpace implements networkingcommon.BackingSpace for testing.

func (*FakeSpace) GoString Uses

func (f *FakeSpace) GoString() string

GoString implements fmt.GoStringer.

func (*FakeSpace) Id Uses

func (f *FakeSpace) Id() string

func (*FakeSpace) Life Uses

func (f *FakeSpace) Life() (life params.Life)

func (*FakeSpace) Name Uses

func (f *FakeSpace) Name() string

func (*FakeSpace) ProviderId Uses

func (f *FakeSpace) ProviderId() (netID network.Id)

func (*FakeSpace) Subnets Uses

func (f *FakeSpace) Subnets() (bs []networkingcommon.BackingSubnet, err error)

func (*FakeSpace) Zones Uses

func (f *FakeSpace) Zones() []string

type FakeSubnet Uses

type FakeSubnet struct {
    Info networkingcommon.BackingSubnetInfo
    // contains filtered or unexported fields
}

FakeSubnet implements networkingcommon.BackingSubnet for testing.

func (*FakeSubnet) AvailabilityZones Uses

func (f *FakeSubnet) AvailabilityZones() []string

func (*FakeSubnet) CIDR Uses

func (f *FakeSubnet) CIDR() string

func (*FakeSubnet) GoString Uses

func (f *FakeSubnet) GoString() string

GoString implements fmt.GoStringer.

func (*FakeSubnet) ID Uses

func (f *FakeSubnet) ID() string

func (*FakeSubnet) Life Uses

func (f *FakeSubnet) Life() life.Value

func (*FakeSubnet) ProviderId Uses

func (f *FakeSubnet) ProviderId() network.Id

func (*FakeSubnet) ProviderNetworkId Uses

func (f *FakeSubnet) ProviderNetworkId() network.Id

func (*FakeSubnet) SpaceID Uses

func (f *FakeSubnet) SpaceID() string

func (*FakeSubnet) SpaceName Uses

func (f *FakeSubnet) SpaceName() string

func (*FakeSubnet) Status Uses

func (f *FakeSubnet) Status() string

func (*FakeSubnet) VLANTag Uses

func (f *FakeSubnet) VLANTag() int

type FakeZone Uses

type FakeZone struct {
    ZoneName      string
    ZoneAvailable bool
}

FakeZone implements providercommon.AvailabilityZone for testing.

func (*FakeZone) Available Uses

func (f *FakeZone) Available() bool

func (*FakeZone) GoString Uses

func (f *FakeZone) GoString() string

GoString implements fmt.GoStringer.

func (*FakeZone) Name Uses

func (f *FakeZone) Name() string

type HTTPRequestParams Uses

type HTTPRequestParams struct {
    // do is used to make the HTTP request.
    // If it is nil, utils.GetNonValidatingHTTPClient().Do will be used.
    // If the body reader implements io.Seeker,
    // req.Body will also implement that interface.
    Do  func(req *http.Request) (*http.Response, error)

    // expectError holds the error regexp to match
    // against the error returned from the HTTP Do
    // request. If it is empty, the error is expected to be
    // nil.
    ExpectError string

    // ExpectStatus holds the expected HTTP status code.
    // http.StatusOK is assumed if this is zero.
    ExpectStatus int

    // tag holds the tag to authenticate as.
    Tag string

    // password holds the password associated with the tag.
    Password string

    // method holds the HTTP method to use for the request.
    Method string

    // url holds the URL to send the HTTP request to.
    URL string

    // contentType holds the content type of the request.
    ContentType string

    // body holds the body of the request.
    Body io.Reader

    // extra headers are added to the http header
    ExtraHeaders map[string]string

    // jsonBody holds an object to be marshaled as JSON
    // as the body of the request. If this is specified, body will
    // be ignored and the Content-Type header will
    // be set to application/json.
    JSONBody interface{}

    // nonce holds the machine nonce to provide in the header.
    Nonce string
}

httpRequestParams holds parameters for the sendHTTPRequest methods.

type Server Uses

type Server struct {
    // Addrs holds the address used for the
    // server, suitable for including in api.Info.Addrs
    Addrs []string

    *httptest.Server
    // contains filtered or unexported fields
}

Server represents a fake API server. It must be closed after use.

func NewAPIServer Uses

func NewAPIServer(newRoot func(modelUUID string) interface{}) *Server

NewAPIServer serves RPC methods on a localhost HTTP server. When a connection is made to the API, the newRoot function is called with the requested model UUID and the returned value defines the API (see the juju/rpc package).

Note that the root value accepts any facade version number - it is not currently possible to use this to serve several different facade versions.

The server uses testing.ServerCert and testing.ServerKey to host the server.

The returned server must be closed after use.

type SetUpFlag Uses

type SetUpFlag bool
const (
    WithZones      SetUpFlag = true
    WithoutZones   SetUpFlag = false
    WithSpaces     SetUpFlag = true
    WithoutSpaces  SetUpFlag = false
    WithSubnets    SetUpFlag = true
    WithoutSubnets SetUpFlag = false
)

type StubBacking Uses

type StubBacking struct {
    *testing.Stub

    EnvConfig *config.Config
    Cloud     environs.CloudSpec

    Zones   []providercommon.AvailabilityZone
    Spaces  []networkingcommon.BackingSpace
    Subnets []networkingcommon.BackingSubnet
}

StubBacking implements networkingcommon.NetworkBacking and records calls to its methods.

func (*StubBacking) AddSpace Uses

func (sb *StubBacking) AddSpace(name string, providerId network.Id, subnets []string, public bool) error

func (*StubBacking) AddSubnet Uses

func (sb *StubBacking) AddSubnet(subnetInfo networkingcommon.BackingSubnetInfo) (networkingcommon.BackingSubnet, error)

func (*StubBacking) AdditionalSubnets Uses

func (sb *StubBacking) AdditionalSubnets()

func (*StubBacking) AllSpaces Uses

func (sb *StubBacking) AllSpaces() ([]networkingcommon.BackingSpace, error)

func (*StubBacking) AllSubnets Uses

func (sb *StubBacking) AllSubnets() ([]networkingcommon.BackingSubnet, error)

func (*StubBacking) AvailabilityZones Uses

func (sb *StubBacking) AvailabilityZones() ([]providercommon.AvailabilityZone, error)

func (*StubBacking) CloudSpec Uses

func (sb *StubBacking) CloudSpec() (environs.CloudSpec, error)

func (*StubBacking) GoString Uses

func (se *StubBacking) GoString() string

GoString implements fmt.GoStringer.

func (*StubBacking) ModelConfig Uses

func (sb *StubBacking) ModelConfig() (*config.Config, error)

func (*StubBacking) ModelTag Uses

func (sb *StubBacking) ModelTag() names.ModelTag

func (*StubBacking) ReloadSpaces Uses

func (sb *StubBacking) ReloadSpaces(environ environs.BootstrapEnviron) error

func (*StubBacking) SetAvailabilityZones Uses

func (sb *StubBacking) SetAvailabilityZones(zones []providercommon.AvailabilityZone) error

func (*StubBacking) SetUp Uses

func (sb *StubBacking) SetUp(c *gc.C, envName string, withZones, withSpaces, withSubnets SetUpFlag)

func (*StubBacking) Subnet Uses

func (sb *StubBacking) Subnet(cidr string) (networkingcommon.BackingSubnet, error)

type StubEnviron Uses

type StubEnviron struct {
    *testing.Stub

    environs.Environ // panic on any not implemented method call
}

StubEnviron is used in tests where environs.Environ is needed.

func (*StubEnviron) GoString Uses

func (se *StubEnviron) GoString() string

GoString implements fmt.GoStringer.

type StubLeaseManager Uses

type StubLeaseManager struct {
    lease.Manager
}

StubLeaseManager pretends to implement lease.Manager. The only method called in this package should be Reader(), implemented below.

func (StubLeaseManager) Reader Uses

func (m StubLeaseManager) Reader(namespace string, modelUUID string) (lease.Reader, error)

Reader returns a StubLeaseReader, which will panic if used.

type StubLeaseReader Uses

type StubLeaseReader struct {
    lease.Reader
}

StubLeaseReader pretends to implement lease.Reader. The non-implemented Leases() method should not be called by tests in the base apiserver package.

type StubMethodCall Uses

type StubMethodCall struct {
    Receiver interface{}
    FuncName string
    Args     []interface{}
}

StubMethodCall is like testing.StubCall, but includes the receiver as well.

func BackingCall Uses

func BackingCall(name string, args ...interface{}) StubMethodCall

BackingCall makes it easy to check method calls on BackingInstance.

func EnvironCall Uses

func EnvironCall(name string, args ...interface{}) StubMethodCall

EnvironCall makes it easy to check method calls on EnvironInstance.

func NetworkingEnvironCall Uses

func NetworkingEnvironCall(name string, args ...interface{}) StubMethodCall

NetworkingEnvironCall makes it easy to check method calls on NetworkingEnvironInstance.

func ProviderCall Uses

func ProviderCall(name string, args ...interface{}) StubMethodCall

ProviderCall makes it easy to check method calls on ProviderInstance.

func ZonedEnvironCall Uses

func ZonedEnvironCall(name string, args ...interface{}) StubMethodCall

ZonedEnvironCall makes it easy to check method calls on ZonedEnvironInstance.

func ZonedNetworkingEnvironCall Uses

func ZonedNetworkingEnvironCall(name string, args ...interface{}) StubMethodCall

ZonedNetworkingEnvironCall makes it easy to check method calls on ZonedNetworkingEnvironInstance.

type StubNetwork Uses

type StubNetwork struct {
}

func (StubNetwork) SetUpSuite Uses

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

type StubNetworkingEnviron Uses

type StubNetworkingEnviron struct {
    *testing.Stub

    environs.NetworkingEnviron // panic on any not implemented method call
}

StubNetworkingEnviron is used in tests where environs.NetworkingEnviron is needed.

func (*StubNetworkingEnviron) GoString Uses

func (se *StubNetworkingEnviron) GoString() string

GoString implements fmt.GoStringer.

func (*StubNetworkingEnviron) Subnets Uses

func (se *StubNetworkingEnviron) Subnets(
    ctx context.ProviderCallContext, instId instance.Id, subIds []network.Id,
) ([]network.SubnetInfo, error)

func (*StubNetworkingEnviron) SupportsSpaces Uses

func (se *StubNetworkingEnviron) SupportsSpaces(ctx context.ProviderCallContext) (bool, error)

type StubPoolHelper Uses

type StubPoolHelper struct {
    StubRelease func() bool
}

StubPoolHelper implements state.PoolHelper

func (StubPoolHelper) Annotate Uses

func (s StubPoolHelper) Annotate(_ string)

func (StubPoolHelper) Release Uses

func (s StubPoolHelper) Release() bool

type StubProvider Uses

type StubProvider struct {
    *testing.Stub

    Zones   []providercommon.AvailabilityZone
    Subnets []network.SubnetInfo

    environs.EnvironProvider // panic on any not implemented method call.
}

StubProvider implements a subset of environs.EnvironProvider methods used in tests.

func (*StubProvider) GoString Uses

func (se *StubProvider) GoString() string

GoString implements fmt.GoStringer.

func (*StubProvider) Open Uses

func (sp *StubProvider) Open(args environs.OpenParams) (environs.Environ, error)

type StubZonedEnviron Uses

type StubZonedEnviron struct {
    *testing.Stub

    providercommon.ZonedEnviron // panic on any not implemented method call
}

StubZonedEnviron is used in tests where providercommon.ZonedEnviron is needed.

func (*StubZonedEnviron) AvailabilityZones Uses

func (se *StubZonedEnviron) AvailabilityZones(ctx context.ProviderCallContext) ([]providercommon.AvailabilityZone, error)

func (*StubZonedEnviron) GoString Uses

func (se *StubZonedEnviron) GoString() string

GoString implements fmt.GoStringer.

type StubZonedNetworkingEnviron Uses

type StubZonedNetworkingEnviron struct {
    *testing.Stub

    // panic on any not implemented method call
    providercommon.ZonedEnviron
    environs.Networking
}

StubZonedNetworkingEnviron is used in tests where features from both environs.Networking and providercommon.ZonedEnviron are needed.

func (*StubZonedNetworkingEnviron) AvailabilityZones Uses

func (se *StubZonedNetworkingEnviron) AvailabilityZones(ctx context.ProviderCallContext) ([]providercommon.AvailabilityZone, error)

func (*StubZonedNetworkingEnviron) GoString Uses

func (se *StubZonedNetworkingEnviron) GoString() string

GoString implements fmt.GoStringer.

func (*StubZonedNetworkingEnviron) Subnets Uses

func (se *StubZonedNetworkingEnviron) Subnets(
    ctx context.ProviderCallContext, instId instance.Id, subIds []network.Id,
) ([]network.SubnetInfo, error)

func (*StubZonedNetworkingEnviron) SupportsSpaces Uses

func (se *StubZonedNetworkingEnviron) SupportsSpaces(ctx context.ProviderCallContext) (bool, error)

Package testing imports 52 packages (graph) and is imported by 24 packages. Updated 2019-10-05. Refresh now. Tools for package owners.