testing

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// ReaderReceivesJobTestCase invokes TestReaderReceivesJob test
	ReaderReceivesJobTestCase = iota

	// ReaderReturnsSameIDTestCase invokes TestReaderReturnsSameID test
	ReaderReturnsSameIDTestCase

	// ReaderErrorsOnEndpointDisapearsTestCase invokes TestReaderErrorsOnEndpointDisapears test
	ReaderErrorsOnEndpointDisapearsTestCase

	// ReaderBacksOffOnEndpointGoneTestCase invokes TestReaderBacksOffOnEndpointGone test
	ReaderBacksOffOnEndpointGoneTestCase
)

Variables

This section is empty.

Functions

func TestReaderCommunication added in v0.6.1

func TestReaderCommunication(t *testing.T, setup func(testCase int) (red reader.DataReader, testMessage string, teardown func()))

TestReaderCommunication runs all essential tests

func TestReaderConstruction

func TestReaderConstruction(t *testing.T, setup setupFunc)

TestReaderConstruction runs all essential tests on object construction.

func TestReaderEndpointManeuvers

func TestReaderEndpointManeuvers(t *testing.T, setup func(testCase int, endpoint string) (red reader.DataReader, err error))

TestReaderEndpointManeuvers runs all tests regarding the endpoint changing state.

Types

type MockConfig

type MockConfig struct {
	MockName      string
	MockTypeName  string
	MockEndpoint  string
	MockRoutePath string
	MockTimeout   time.Duration
	MockInterval  time.Duration
	MockBackoff   int
	MockLogger    logrus.FieldLogger
}

MockConfig is used for instantiating a mock reader

func NewMockConfig

func NewMockConfig(name, typeName string, log logrus.FieldLogger, endpoint, routepath string, interval, timeout time.Duration, backoff int) (*MockConfig, error)

NewMockConfig returns a mocked version of the config

func (*MockConfig) Backoff

func (c *MockConfig) Backoff() int

Backoff returns the backoff

func (*MockConfig) Endpoint

func (c *MockConfig) Endpoint() string

Endpoint returns the endpoint

func (*MockConfig) Interval

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

Interval returns the interval

func (*MockConfig) Logger

func (c *MockConfig) Logger() logrus.FieldLogger

Logger returns the logger

func (*MockConfig) Name

func (c *MockConfig) Name() string

Name returns the name

func (*MockConfig) NewInstance

func (c *MockConfig) NewInstance(ctx context.Context) (reader.DataReader, error)

NewInstance returns a mocked version of the config

func (*MockConfig) RoutePath

func (c *MockConfig) RoutePath() string

RoutePath returns the routepath

func (*MockConfig) Timeout

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

Timeout returns the timeout

func (*MockConfig) TypeName

func (c *MockConfig) TypeName() string

TypeName returns the typename

type SimpleReader

type SimpleReader struct {
	ReadFunc func(context.Context) (*reader.ReadJobResult, error)
	// contains filtered or unexported fields
}

SimpleReader is useful for testing purposes.

Example (Read)
log := lib.DiscardLogger()
ctx := context.Background()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, `{"the key": "is the value!"}`)
}))
defer ts.Close()

red, _ := NewSimpleReader(log, ts.URL, "reader_example", "reader_example", 10*time.Millisecond, 10*time.Millisecond, 10)

// Issuing a job
res, err := red.Read(communication.NewReadJob(ctx))
// Lets check the errors
if err == nil {
	fmt.Println("No errors reported")
}

// Let's read what it retrieved
fmt.Println("Result is:", string(res.Res))
Output:

No errors reported
Result is: {"the key": "is the value!"}

func NewSimpleReader

func NewSimpleReader(
	log logrus.FieldLogger,
	endpoint string,
	name,
	typeName string,
	interval,
	timeout time.Duration,
	backoff int,
) (*SimpleReader, error)

NewSimpleReader is a reader for using in tests

func (*SimpleReader) Interval

func (m *SimpleReader) Interval() time.Duration

Interval returns the interval

func (*SimpleReader) Mapper

func (m *SimpleReader) Mapper() datatype.Mapper

Mapper returns the mapper

func (*SimpleReader) Name

func (m *SimpleReader) Name() string

Name returns the name

func (*SimpleReader) Read

Read executes the ReadFunc if defined, otherwise continues normally

func (*SimpleReader) Timeout

func (m *SimpleReader) Timeout() time.Duration

Timeout returns the timeout

func (*SimpleReader) TypeName

func (m *SimpleReader) 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