golang-stuff: github.com/milliyang/golang-stuff/github.com/globocom/tsuru/testing Index | Files

package testing

import "github.com/milliyang/golang-stuff/github.com/globocom/tsuru/testing"

Package testing provide test helpers for various actions.

Index

Package Files

checker.go provisioner.go queue.go setup.go smtp.go transport.go

Variables

var IsRecorded gocheck.Checker = isRecordedChecker{}

func CleanQ Uses

func CleanQ(names ...string)

CleanQ deletes all messages from queues identified by the given names.

type Action Uses

type Action struct {
    User   string
    Action string
    Extra  []interface{}
}

type Cmd Uses

type Cmd struct {
    Cmd  string
    Args []string
    App  provision.App
}

type ConditionalTransport Uses

type ConditionalTransport struct {
    Transport
    CondFunc func(*http.Request) bool
}

func (*ConditionalTransport) RoundTrip Uses

func (t *ConditionalTransport) RoundTrip(req *http.Request) (*http.Response, error)

type FakeApp Uses

type FakeApp struct {
    Commands []string
    // contains filtered or unexported fields
}

Fake implementation for provision.App.

func NewFakeApp Uses

func NewFakeApp(name, platform string, units int) *FakeApp

func (*FakeApp) AddUnit Uses

func (a *FakeApp) AddUnit(u *FakeUnit)

func (*FakeApp) GetCommands Uses

func (a *FakeApp) GetCommands() []string

func (*FakeApp) GetName Uses

func (a *FakeApp) GetName() string

func (*FakeApp) GetPlatform Uses

func (a *FakeApp) GetPlatform() string

func (*FakeApp) HasLog Uses

func (a *FakeApp) HasLog(source, message string) bool

func (*FakeApp) IsReady Uses

func (a *FakeApp) IsReady() bool

func (*FakeApp) Log Uses

func (a *FakeApp) Log(message, source string) error

func (*FakeApp) Logs Uses

func (a *FakeApp) Logs() []string

func (*FakeApp) ProvisionedUnits Uses

func (a *FakeApp) ProvisionedUnits() []provision.AppUnit

func (*FakeApp) Ready Uses

func (a *FakeApp) Ready() error

func (*FakeApp) RemoveUnit Uses

func (a *FakeApp) RemoveUnit(id string) error

func (*FakeApp) Restart Uses

func (a *FakeApp) Restart(w io.Writer) error

func (*FakeApp) Run Uses

func (a *FakeApp) Run(cmd string, w io.Writer) error

func (*FakeApp) SerializeEnvVars Uses

func (a *FakeApp) SerializeEnvVars() error

func (*FakeApp) SetUnitStatus Uses

func (a *FakeApp) SetUnitStatus(s provision.Status, index int)

type FakeProvisioner Uses

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

Fake implementation for provision.Provisioner.

func NewFakeProvisioner Uses

func NewFakeProvisioner() *FakeProvisioner

func (*FakeProvisioner) AddUnits Uses

func (p *FakeProvisioner) AddUnits(app provision.App, n uint) ([]provision.Unit, error)

func (*FakeProvisioner) Addr Uses

func (p *FakeProvisioner) Addr(app provision.App) (string, error)

func (*FakeProvisioner) CollectStatus Uses

func (p *FakeProvisioner) CollectStatus() ([]provision.Unit, error)

func (*FakeProvisioner) Deploy Uses

func (p *FakeProvisioner) Deploy(app provision.App, version string, w io.Writer) error

func (*FakeProvisioner) Destroy Uses

func (p *FakeProvisioner) Destroy(app provision.App) error

func (*FakeProvisioner) ExecuteCommand Uses

func (p *FakeProvisioner) ExecuteCommand(stdout, stderr io.Writer, app provision.App, cmd string, args ...string) error

ExecuteCommand will pretend to execute the given command, recording data about it.

The output of the command must be prepared with PrepareOutput, and failures must be prepared with PrepareFailure. In case of failure, the prepared output will be sent to the standard error stream, otherwise, it will be sent to the standard error stream.

When there is no output nor failure prepared, ExecuteCommand will return a timeout error.

func (*FakeProvisioner) GetCmds Uses

func (p *FakeProvisioner) GetCmds(cmd string, app provision.App) []Cmd

Returns the number of calls to restart. GetCmds returns a list of commands executed in an app. If you don't specify the command (an empty string), it will return all commands executed in the given app.

func (*FakeProvisioner) GetUnits Uses

func (p *FakeProvisioner) GetUnits(app provision.App) []provision.Unit

func (*FakeProvisioner) HasCName Uses

func (p *FakeProvisioner) HasCName(app provision.App, cname string) bool

func (*FakeProvisioner) InstallDeps Uses

func (p *FakeProvisioner) InstallDeps(app provision.App, w io.Writer) error

func (*FakeProvisioner) InstalledDeps Uses

func (p *FakeProvisioner) InstalledDeps(app provision.App) int

InstalledDeps returns the number of InstallDeps calls for the given app.

func (*FakeProvisioner) PrepareFailure Uses

func (p *FakeProvisioner) PrepareFailure(method string, err error)

PrepareFailure prepares a failure for the given method name.

For instance, PrepareFailure("Deploy", errors.New("Deploy failed")) will cause next Deploy call to return the given error. Multiple calls to this method will enqueue failures, i.e. three calls to PrepareFailure("Deploy"...) means that the three next Deploy call will fail.

func (*FakeProvisioner) PrepareOutput Uses

func (p *FakeProvisioner) PrepareOutput(b []byte)

PrepareOutput sends the given slice of bytes to a queue of outputs.

Each prepared output will be used in the ExecuteCommand. It might be sent to the standard output or standard error. See ExecuteCommand docs for more details.

func (*FakeProvisioner) Provision Uses

func (p *FakeProvisioner) Provision(app provision.App) error

func (*FakeProvisioner) Provisioned Uses

func (p *FakeProvisioner) Provisioned(app provision.App) bool

Provisioned checks whether the given app has been provisioned.

func (*FakeProvisioner) RemoveUnit Uses

func (p *FakeProvisioner) RemoveUnit(app provision.App, name string) error

func (*FakeProvisioner) Reset Uses

func (p *FakeProvisioner) Reset()

Reset cleans up the FakeProvisioner, deleting all apps and their data. It also deletes prepared failures and output. It's like calling NewFakeProvisioner again, without all the allocations.

func (*FakeProvisioner) Restart Uses

func (p *FakeProvisioner) Restart(app provision.App) error

func (*FakeProvisioner) Restarts Uses

func (p *FakeProvisioner) Restarts(app provision.App) int

Restarts returns the number of restarts for a given app.

func (*FakeProvisioner) SetCName Uses

func (p *FakeProvisioner) SetCName(app provision.App, cname string) error

func (FakeProvisioner) Swap Uses

func (FakeProvisioner) Swap(app1, app2 provision.App) error

func (*FakeProvisioner) UnsetCName Uses

func (p *FakeProvisioner) UnsetCName(app provision.App, cname string) error

func (*FakeProvisioner) Version Uses

func (p *FakeProvisioner) Version(app provision.App) string

Version returns the last deployed for a given app.

type FakeQ Uses

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

func (*FakeQ) Delete Uses

func (q *FakeQ) Delete(m *queue.Message) error

func (*FakeQ) Get Uses

func (q *FakeQ) Get(timeout time.Duration) (*queue.Message, error)

func (*FakeQ) Put Uses

func (q *FakeQ) Put(m *queue.Message, delay time.Duration) error

func (*FakeQ) Release Uses

func (q *FakeQ) Release(m *queue.Message, delay time.Duration) error

type FakeQFactory Uses

type FakeQFactory struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func NewFakeQFactory Uses

func NewFakeQFactory() *FakeQFactory

func (*FakeQFactory) Get Uses

func (f *FakeQFactory) Get(name string) (queue.Q, error)

func (*FakeQFactory) Handler Uses

func (f *FakeQFactory) Handler(fn func(*queue.Message), names ...string) (queue.Handler, error)

type FakeUnit Uses

type FakeUnit struct {
    Name       string
    Ip         string
    InstanceId string
    Machine    int
    Status     provision.Status
}

Fake implementation for provision.Unit.

func (*FakeUnit) GetInstanceId Uses

func (u *FakeUnit) GetInstanceId() string

func (*FakeUnit) GetIp Uses

func (u *FakeUnit) GetIp() string

func (*FakeUnit) GetMachine Uses

func (u *FakeUnit) GetMachine() int

func (*FakeUnit) GetName Uses

func (u *FakeUnit) GetName() string

func (*FakeUnit) GetStatus Uses

func (u *FakeUnit) GetStatus() provision.Status

type Mail Uses

type Mail struct {
    From string
    To   []string
    Data []byte
}

Mail represents an email message that has been sent to the fake server.

type SMTPServer Uses

type SMTPServer struct {
    // MailBox is the slice that stores all messages that has arrived to
    // the server while it's listening. Use the mutex to access it, or bad
    // things can happen.
    MailBox []Mail
    sync.RWMutex
    // contains filtered or unexported fields
}

SMTPServer is a fake SMTP server implementation.

This SMTP server does not support authentication and is supposed to be used in tests only.

Use NewSMTPServer create a new instance and start serving; SMTPServer.Addr() will get you the address of the server and Stop will stop the server, closing the listener. Every message that arrive at the server is stored in the MailBox slice.

func NewSMTPServer Uses

func NewSMTPServer() (*SMTPServer, error)

NewSMTPServer creates a new SMTP server, for testing purposes.

func (*SMTPServer) Addr Uses

func (s *SMTPServer) Addr() string

Addr returns the address of the server, in the form <host>:<port>.

func (*SMTPServer) Reset Uses

func (s *SMTPServer) Reset()

Reset resets the server, cleaning up the mailbox.

func (*SMTPServer) Stop Uses

func (s *SMTPServer) Stop()

Stop stops the server. It's safe to call this method multiple times.

type T Uses

type T struct {
    Admin        user
    AdminTeam    team
    S3Server     *s3test.Server
    IamServer    *iamtest.Server
    GitAPIServer string
    GitRWHost    string
    GitROHost    string
}

func (*T) RollbackGitConfs Uses

func (t *T) RollbackGitConfs(c *gocheck.C)

func (*T) SetGitConfs Uses

func (t *T) SetGitConfs(c *gocheck.C)

func (*T) StartAmzS3AndIAM Uses

func (t *T) StartAmzS3AndIAM(c *gocheck.C)

func (*T) StartGandalfTestServer Uses

func (t *T) StartGandalfTestServer(h http.Handler) *httptest.Server

starts a new httptest.Server and returns it Also changes git:host, git:port and git:protocol to match the server's url

type Transport Uses

type Transport struct {
    Message string
    Status  int
    Headers map[string][]string
}

func (*Transport) RoundTrip Uses

func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

Package testing imports 21 packages (graph). Updated 2017-10-20. Refresh now. Tools for package owners.