testing

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testing is a test suit for readers. They should provide an object that implements the Constructor interface then run:

import rt "github.com/arsham/expipe/reader/testing"
....
type Construct struct {
    *rt.BaseConstruct
    testServer *httptest.Server
}

func (c *Construct) TestServer() *httptest.Server {
    return /* a test server */
}

func (c *Construct) Object() (reader.DataReader, error) {
    return expvar.New(c.Setters()...)
}

func TestMyReader(t *testing.T) {
    rt.TestSuites(t, func() (rt.Constructor, func()) {
        c := &Construct{
            testServer:    getTestServer(),
            BaseConstruct: rt.NewBaseConstruct(),
        }
        return c, func() { c.testServer.Close() }
    })
}

The test suit will pick it up and does all the tests.

Important Note

The test suite might close and request the test server multiple times during its work. Make sure you return a brand new instance every time the TestServer method is been called. All tests are ran in isolation and they are set to be run as parallel. Make sure your code doesn't have any race conditions. You need to write the edge cases if they are not covered in this section.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestSuites added in v0.8.1

func TestSuites(t *testing.T, setup func() (Constructor, func()))

TestSuites returns a map of test name to the runner function.

Types

type BaseConstruct added in v0.10.0

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

BaseConstruct implements Constructor interface. It only remembers the setter functions, therefore you need to apply them when creating an object in the derived constructor. It is concurrent safe.

func NewBaseConstruct added in v0.10.0

func NewBaseConstruct() *BaseConstruct

NewBaseConstruct returns an instance of BaseConstruct.

func (*BaseConstruct) SetBackoff added in v0.10.0

func (b *BaseConstruct) SetBackoff(backoff int)

SetBackoff adds a Backoff value to setter configuration.

func (*BaseConstruct) SetEndpoint added in v0.10.0

func (b *BaseConstruct) SetEndpoint(endpoint string)

SetEndpoint adds a Endpoint value to setter configuration.

func (*BaseConstruct) SetInterval added in v0.10.0

func (b *BaseConstruct) SetInterval(interval time.Duration)

SetInterval adds a Interval value to setter configuration.

func (*BaseConstruct) SetLogger added in v0.10.0

func (b *BaseConstruct) SetLogger(logger tools.FieldLogger)

SetLogger adds a Logger value to setter configuration.

func (*BaseConstruct) SetMapper added in v0.10.0

func (b *BaseConstruct) SetMapper(mapper datatype.Mapper)

SetMapper adds a Mapper value to setter configuration.

func (*BaseConstruct) SetName added in v0.10.0

func (b *BaseConstruct) SetName(name string)

SetName adds a Name value to setter configuration.

func (*BaseConstruct) SetTimeout added in v0.10.0

func (b *BaseConstruct) SetTimeout(timeout time.Duration)

SetTimeout adds a Timeout value to setter configuration.

func (*BaseConstruct) SetTypeName added in v0.10.0

func (b *BaseConstruct) SetTypeName(typeName string)

SetTypeName adds a TypeName value to setter configuration.

func (*BaseConstruct) Setters added in v0.10.0

func (b *BaseConstruct) Setters() []func(reader.Constructor) error

Setters returns a copy of the configuration functions.

type Config added in v0.7.0

type Config struct {
	MockName     string
	MockTypeName string
	MockEndpoint string
	MockTimeout  time.Duration
	MockInterval time.Duration
	MockBackoff  int
	MockLogger   tools.FieldLogger
}

Config is used for instantiating a mock reader.

func (*Config) Backoff added in v0.7.0

func (c *Config) Backoff() int

Backoff returns the backoff.

func (*Config) Endpoint added in v0.7.0

func (c *Config) Endpoint() string

Endpoint returns the endpoint.

func (*Config) Interval added in v0.7.0

func (c *Config) Interval() time.Duration

Interval returns the interval.

func (*Config) Logger added in v0.7.0

func (c *Config) Logger() tools.FieldLogger

Logger returns the logger.

func (*Config) Name added in v0.7.0

func (c *Config) Name() string

Name returns the name.

func (*Config) Reader added in v0.10.0

func (c *Config) Reader() (reader.DataReader, error)

Reader implements the ReaderConf interface.

func (*Config) Timeout added in v0.7.0

func (c *Config) Timeout() time.Duration

Timeout returns the timeout.

func (*Config) TypeName added in v0.7.0

func (c *Config) TypeName() string

TypeName returns the typeName.

type Constructor added in v0.7.0

type Constructor interface {
	reader.Constructor
	TestServer() *httptest.Server
	Object() (reader.DataReader, error)
}

Constructor is an interface for setting up an object for testing. TestServer should return a ready to use test server Object should return the instantiated object

type Reader added in v0.7.0

type Reader struct {
	MockName     string
	MockTypeName string
	MockEndpoint string
	MockMapper   datatype.Mapper

	MockInterval time.Duration

	ReadFunc func(*token.Context) (*reader.Result, error)
	PingFunc func() error
	Pinged   bool
	// contains filtered or unexported fields
}

Reader is useful for testing purposes.

func GetReader added in v0.7.0

func GetReader(url string) *Reader

GetReader provides a MockReader for using in the example.

func New added in v0.7.0

func New(options ...func(reader.Constructor) error) (*Reader, error)

New is a reader for using in tests.

func (*Reader) Backoff added in v0.8.1

func (r *Reader) Backoff() int

Backoff returns the backoff.

func (*Reader) Endpoint added in v0.8.1

func (r *Reader) Endpoint() string

Endpoint returns the endpoint.

func (*Reader) Interval added in v0.7.0

func (r *Reader) Interval() time.Duration

Interval returns the interval.

func (*Reader) Logger added in v0.8.1

func (r *Reader) Logger() tools.FieldLogger

Logger returns the log.

func (*Reader) Mapper added in v0.7.0

func (r *Reader) Mapper() datatype.Mapper

Mapper returns the mapper.

func (*Reader) Name added in v0.7.0

func (r *Reader) Name() string

Name returns the name.

func (*Reader) Ping added in v0.7.0

func (r *Reader) Ping() error

Ping pings the endpoint and return nil if was successful.

func (*Reader) Read added in v0.7.0

func (r *Reader) Read(job *token.Context) (*reader.Result, error)

Read executes the ReadFunc if defined, otherwise continues normally.

func (*Reader) SetBackoff added in v0.8.1

func (r *Reader) SetBackoff(backoff int)

SetBackoff sets the backoff of the reader.

func (*Reader) SetEndpoint added in v0.8.1

func (r *Reader) SetEndpoint(endpoint string)

SetEndpoint sets the endpoint of the reader.

func (*Reader) SetInterval added in v0.8.1

func (r *Reader) SetInterval(interval time.Duration)

SetInterval sets the interval of the reader.

func (*Reader) SetLogger added in v0.8.1

func (r *Reader) SetLogger(log tools.FieldLogger)

SetLogger sets the log of the reader.

func (*Reader) SetMapper added in v0.8.1

func (r *Reader) SetMapper(mapper datatype.Mapper)

SetMapper sets the mapper of the reader.

func (*Reader) SetName added in v0.8.1

func (r *Reader) SetName(name string)

SetName sets the name of the reader.

func (*Reader) SetTimeout added in v0.8.1

func (r *Reader) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout of the reader.

func (*Reader) SetTypeName added in v0.8.1

func (r *Reader) SetTypeName(typeName string)

SetTypeName sets the type name of the reader.

func (*Reader) Timeout added in v0.7.0

func (r *Reader) Timeout() time.Duration

Timeout returns the timeout.

func (*Reader) TypeName added in v0.7.0

func (r *Reader) TypeName() string

TypeName returns the type name.

Jump to

Keyboard shortcuts

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