1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// Package testing provides a stub implementation that can be used for
// simplified testing of applications that normally use tableflip.
// It is also helpful for allowing projects that use tableflip
// able to run on Windows, which does not support tableflip.
package testing
import (
"context"
"github.com/cloudflare/tableflip"
)
// Upgrader has all the methods of tableflip.Upgrader, but they don't
// actually do anything special.
type Upgrader struct {
*Fds
}
// New creates a new stub Upgrader.
//
// Unlike the real version, this can be called many times.
func New() (*Upgrader, error) {
upg := newStubUpgrader()
return upg, nil
}
func newStubUpgrader() *Upgrader {
return &Upgrader{
&Fds{},
}
}
// Ready does nothing, since it is impossible to inherit with
// the stub implementation.
// However, the function still needs to be callable without errors
// in order to be useful.
func (u *Upgrader) Ready() error {
return nil
}
// Exit returns a channel which is closed when the process should
// exit.
// We can return nil here because reading from a nil channel blocks
func (u *Upgrader) Exit() <-chan struct{} {
return nil
}
// Stop does nothing, since there will never be anything to stop
// in the stub implementation
func (u *Upgrader) Stop() {
}
// WaitForParent returns immediately, since the stub implementation
// can never be a parent
func (u *Upgrader) WaitForParent(ctx context.Context) error {
return nil
}
// HasParent is always false, since the stub implementation can never
// have a parent
func (u *Upgrader) HasParent() bool {
return false
}
// Upgrade always returns an error in the stub implementation,
// since nothing can be done.
func (u *Upgrader) Upgrade() error {
return tableflip.ErrNotSupported
}
|