Documentation
¶
Index ¶
- Constants
- func TestReaderCommunication(t *testing.T, ...)
- func TestReaderConstruction(t *testing.T, setup setupFunc)
- func TestReaderEndpointManeuvers(t *testing.T, ...)
- type MockConfig
- func (c *MockConfig) Backoff() int
- func (c *MockConfig) Endpoint() string
- func (c *MockConfig) Interval() time.Duration
- func (c *MockConfig) Logger() logrus.FieldLogger
- func (c *MockConfig) Name() string
- func (c *MockConfig) NewInstance(ctx context.Context) (reader.DataReader, error)
- func (c *MockConfig) RoutePath() string
- func (c *MockConfig) Timeout() time.Duration
- func (c *MockConfig) TypeName() string
- type SimpleReader
- func (m *SimpleReader) Interval() time.Duration
- func (m *SimpleReader) Mapper() datatype.Mapper
- func (m *SimpleReader) Name() string
- func (m *SimpleReader) Read(job context.Context) (*reader.ReadJobResult, error)
- func (m *SimpleReader) Timeout() time.Duration
- func (m *SimpleReader) TypeName() string
Examples ¶
Constants ¶
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 ¶
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) 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) 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
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) Read ¶
func (m *SimpleReader) Read(job context.Context) (*reader.ReadJobResult, error)
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