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: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// RecorderReceivesPayloadTestCase is for invoking TestRecorderReceivesPayload test
	RecorderReceivesPayloadTestCase = iota

	// RecorderSendsResultTestCase is for invoking TestRecorderSendsResult test
	RecorderSendsResultTestCase

	// RecorderClosesTestCase is for invoking TestRecorderCloses test
	RecorderClosesTestCase

	// RecorderErrorsOnUnavailableEndpointTestCase is for invoking TestRecorderErrorsOnUnavailableEndpoint test
	RecorderErrorsOnUnavailableEndpointTestCase

	// RecorderBacksOffOnEndpointGoneTestCase invokes TestRecorderBacksOffOnEndpointGone test
	RecorderBacksOffOnEndpointGoneTestCase

	// RecorderConstructionCasesTestCase is for invoking TestRecorderConstructionCases test
	RecorderConstructionCasesTestCase

	// RecorderErrorsOnInvalidEndpointTestCase is for invoking TestRecorderErrorsOnInvalidEndpoint test
	RecorderErrorsOnInvalidEndpointTestCase
)

Variables

This section is empty.

Functions

func TestRecorderCommunication added in v0.6.1

func TestRecorderCommunication(t *testing.T, setup func(testCase int) (ctx context.Context, rec recorder.DataRecorder, err error, teardown func()))

TestRecorderCommunication runs all essential tests.

func TestRecorderConstruction

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

TestRecorderConstruction runs all essential tests on object construction.

func TestRecorderEndpointManeuvers

func TestRecorderEndpointManeuvers(t *testing.T, setup func(testCase int) (ctx context.Context, rec recorder.DataRecorder, err error, teardown func()))

TestRecorderEndpointManeuvers runs all tests regarding the endpoint changing state.

Types

type MockConfig

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

MockConfig holds the necessary configuration for setting up an elasticsearch reader endpoint.

func NewMockConfig

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

NewMockConfig returns a mocked object

func (*MockConfig) Backoff

func (m *MockConfig) Backoff() int

Backoff is the mocked version

func (*MockConfig) Endpoint

func (m *MockConfig) Endpoint() string

Endpoint is the mocked version

func (*MockConfig) IndexName

func (m *MockConfig) IndexName() string

IndexName is the mocked version

func (*MockConfig) Logger

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

Logger is the mocked version

func (*MockConfig) Name

func (m *MockConfig) Name() string

Name is the mocked version

func (*MockConfig) NewInstance

func (m *MockConfig) NewInstance(ctx context.Context) (recorder.DataRecorder, error)

NewInstance returns a mocked object

func (*MockConfig) RoutePath

func (m *MockConfig) RoutePath() string

RoutePath is the mocked version

func (*MockConfig) Timeout

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

Timeout is the mocked version

type SimpleRecorder

type SimpleRecorder struct {
	ErrorFunc func() error

	Smu        sync.RWMutex
	RecordFunc func(context.Context, *recorder.RecordJob) error
	// contains filtered or unexported fields
}

SimpleRecorder is designed to be used in tests

Example
var err error
log := lib.DiscardLogger()
ctx := context.Background()
receivedPayload := make(chan string)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	receivedPayload <- "I have received the payload!"
}))
defer ts.Close()

rec, _ := NewSimpleRecorder(ctx, log, "reader_example", ts.URL, "intexName", time.Second, 5)
payload := datatype.NewContainer([]datatype.DataType{
	datatype.StringType{Key: "key", Value: "value"},
})
job := &recorder.RecordJob{
	Payload:   payload,
	IndexName: "my index",
	Time:      time.Now(),
}
// Issuing a job
go func() {
	err = rec.Record(ctx, job)
	// Lets check the errors
	if err != nil {
		panic("Wasn't expecting any errors")
	}
}()
fmt.Println(<-receivedPayload)
fmt.Println("No errors reported")

// Issuing another job
go rec.Record(ctx, job)
fmt.Println(<-receivedPayload)
Output:

I have received the payload!
No errors reported
I have received the payload!

func NewSimpleRecorder

func NewSimpleRecorder(ctx context.Context, log logrus.FieldLogger, name, endpoint, indexName string, timeout time.Duration, backoff int) (*SimpleRecorder, error)

NewSimpleRecorder returns a SimpleRecorder instance

func (*SimpleRecorder) IndexName

func (s *SimpleRecorder) IndexName() string

IndexName returns the indexname

func (*SimpleRecorder) Name

func (s *SimpleRecorder) Name() string

Name returns the name

func (*SimpleRecorder) Record

func (s *SimpleRecorder) Record(ctx context.Context, job *recorder.RecordJob) error

Record calls the RecordFunc if exists, otherwise continues as normal

func (*SimpleRecorder) Timeout

func (s *SimpleRecorder) Timeout() time.Duration

Timeout returns the timeout

Jump to

Keyboard shortcuts

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