Documentation
¶
Overview ¶
Package testing is a test suit for recorders. They should provide an object that implements the Constructor interface then run:
import recorder_test "github.com/arsham/expipe/recorder/testing" .... r, err := recorder_test.New() if err != nil { panic(err) } c := &Construct{r, getTestServer()} recorder_test.TestSuites(t, c)
The test suit will pick it up and does all the tests.
Important Note ¶
You need to write the edge cases if they are not covered in this section.
Index ¶
- func TestSuites(t *testing.T, cons Constructor)
- type Config
- type Constructor
- type Recorder
- func (r *Recorder) Backoff() int
- func (r *Recorder) Endpoint() string
- func (r *Recorder) IndexName() string
- func (r *Recorder) Logger() internal.FieldLogger
- func (r *Recorder) Name() string
- func (r *Recorder) Ping() error
- func (r *Recorder) Record(ctx context.Context, job *recorder.Job) error
- func (r *Recorder) SetBackoff(backoff int)
- func (r *Recorder) SetEndpoint(endpoint string)
- func (r *Recorder) SetIndexName(indexName string)
- func (r *Recorder) SetLogger(log internal.FieldLogger)
- func (r *Recorder) SetName(name string)
- func (r *Recorder) SetTimeout(timeout time.Duration)
- func (r *Recorder) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestSuites ¶ added in v0.8.1
func TestSuites(t *testing.T, cons Constructor)
TestSuites returns a map of test name to the runner function.
Types ¶
type Config ¶ added in v0.7.0
type Config struct { MockName string MockEndpoint string MockTimeout time.Duration MockBackoff int MockIndexName string MockLogger internal.FieldLogger }
Config holds the necessary configuration for setting up an elasticsearch recorder endpoint.
func NewConfig ¶ added in v0.7.0
func NewConfig(name string, log internal.FieldLogger, endpoint string, timeout time.Duration, backoff int, indexName string) (*Config, error)
NewConfig returns a mocked object
func (*Config) Logger ¶ added in v0.7.0
func (c *Config) Logger() internal.FieldLogger
Logger is the mocked version
func (*Config) NewInstance ¶ added in v0.7.0
func (c *Config) NewInstance() (recorder.DataRecorder, error)
NewInstance returns a mocked object
type Constructor ¶ added in v0.7.0
type Constructor interface { recorder.Constructor // ValidEndpoints should return a list of valid endpoints ValidEndpoints() []string // InvalidEndpoints should return a list of invalid endpoints InvalidEndpoints() []string // TestServer should return a ready to use test server TestServer() *httptest.Server // Object should return the instantiated object Object() (recorder.DataRecorder, error) }
Constructor is an interface for setting up an object for testing.
type Recorder ¶ added in v0.7.0
type Recorder struct { ErrorFunc func() error Smu sync.RWMutex RecordFunc func(context.Context, *recorder.Job) error Pinged bool // contains filtered or unexported fields }
Recorder is designed to be used in tests.
func GetRecorder ¶ added in v0.7.0
GetRecorder provides a SimpleRecorder for using in the example.
func New ¶ added in v0.7.0
func New(options ...func(recorder.Constructor) error) (*Recorder, error)
New is a recorder for using in tests
func (*Recorder) Logger ¶ added in v0.8.1
func (r *Recorder) Logger() internal.FieldLogger
Logger returns the log
func (*Recorder) Record ¶ added in v0.7.0
Record calls the RecordFunc if exists, otherwise continues as normal
func (*Recorder) SetBackoff ¶ added in v0.8.1
SetBackoff sets the backoff of the recorder
func (*Recorder) SetEndpoint ¶ added in v0.8.1
SetEndpoint sets the endpoint of the recorder
func (*Recorder) SetIndexName ¶ added in v0.8.1
SetIndexName sets the index name of the recorder
func (*Recorder) SetLogger ¶ added in v0.8.1
func (r *Recorder) SetLogger(log internal.FieldLogger)
SetLogger sets the log of the recorder
func (*Recorder) SetTimeout ¶ added in v0.8.1
SetTimeout sets the timeout of the recorder