Documentation
¶
Index ¶
- Constants
- func TestRecorderCommunication(t *testing.T, ...)
- func TestRecorderConstruction(t *testing.T, setup setupFunc)
- func TestRecorderEndpointManeuvers(t *testing.T, ...)
- type MockConfig
- func (m *MockConfig) Backoff() int
- func (m *MockConfig) Endpoint() string
- func (m *MockConfig) IndexName() string
- func (m *MockConfig) Logger() logrus.FieldLogger
- func (m *MockConfig) Name() string
- func (m *MockConfig) NewInstance(ctx context.Context) (recorder.DataRecorder, error)
- func (m *MockConfig) RoutePath() string
- func (m *MockConfig) Timeout() time.Duration
- type SimpleRecorder
Examples ¶
Constants ¶
const ( // RecorderReceivesPayloadTestCase is for invoking TestRecorderReceivesPayload test RecorderReceivesPayloadTestCase = iota // RecorderSendsResultTestCase is for invoking TestRecorderSendsResult test RecorderSendsResultTestCase // RecorderClosesTestCase is for invoking TestRecorderCloses test RecorderClosesTestCase 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 ¶
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) 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) 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) Record ¶
Record calls the RecordFunc if exists, otherwise continues as normal
func (*SimpleRecorder) Timeout ¶
func (s *SimpleRecorder) Timeout() time.Duration
Timeout returns the timeout