Documentation ¶
Index ¶
- Variables
- func NewJobProcessor() *divider.JobProcessor
- func ProviderNonTerminalErrorTest(t *testing.T, provider divider.JobProvider)
- func ProviderTerminalErrorTest(t *testing.T, provider divider.JobProvider)
- func RunTestCases(t *testing.T, run func(*testing.T, TestCase))
- func Validate(t *testing.T, test TestCase, actual []*divider.JobResult)
- type BrokenWriter
- type FailFn
- type Failer
- type FakeJobProvider
- type FakeResultReporter
- type FakeWriter
- type TestCase
Constants ¶
This section is empty.
Variables ¶
var ( // FakeLog is used with mocked JobProcessor. // By default it uses writer that drops messages. FakeLog = log.New(NewFakeWriter(), "", log.LstdFlags) // FakeDivider is used with mocked JobProcessor. // By default it is godiv.Divider. FakeDivider = godiv.Divider // TerminalErrorFailFn special error different to divider.NonTerminalError. // It is introduced in order to validate behaviour of JobProvider. TerminalErrorFailFn = NewErrFailFn(errors.New("terminal error")) // NonTerminalErrorFailFn returns empty divider.NonTerminalError NonTerminalErrorFailFn = NewErrFailFn(divider.NewNonTerminalError(nil)) )
var ( // ErrBrokenWriter raised by BrokenWriter after n bytes written. ErrBrokenWriter = errors.New("Writer is broken") // ErrPanicWriter is an error PanicWritter panics with. ErrPanicWriter = errors.New("Panic should happen") // PanicFailFn panics with ErrPanicWriter. PanicFailFn = func() error { panic(ErrPanicWriter) } // StuckFailFn introduces a delay of 1s. StuckFailFn = func() error { <-time.After(time.Second); return nil } )
var AllValid = TestCase{ Name: "All valid", Jobs: []*divider.Job{ ÷r.Job{Arg1: 2, Arg2: 2, Valid: true}, ÷r.Job{Arg1: 0, Arg2: 2, Valid: true}, ÷r.Job{Arg1: 4, Arg2: -2, Valid: true}, ÷r.Job{Arg1: -4, Arg2: 2, Valid: true}, }, Results: []*divider.JobResult{ ÷r.JobResult{ID: 0, Value: 1, Valid: true}, ÷r.JobResult{ID: 1, Value: 0, Valid: true}, ÷r.JobResult{ID: 2, Value: -2, Valid: true}, ÷r.JobResult{ID: 3, Value: -2, Valid: true}, }, Err: nil, }
AllValid includes only valid jobs.
var InvalidJob = TestCase{ Name: "Invalid job", Jobs: []*divider.Job{ ÷r.Job{Arg1: 2, Arg2: 0, Valid: true}, ÷r.Job{Arg1: 0, Arg2: 0, Valid: false}, ÷r.Job{Arg1: 2, Arg2: 2, Valid: true}, }, Results: []*divider.JobResult{ ÷r.JobResult{ID: 0, Value: 0, Valid: false}, ÷r.JobResult{ID: 1, Value: 0, Valid: false}, ÷r.JobResult{ID: 2, Value: 1, Valid: true}, }, Err: nil, }
InvalidJob includes at least one job that has error and should not be processed. The case is only for JobProcessor worker testing.
var ProcessingError = TestCase{ Name: "Processing error", Jobs: []*divider.Job{ ÷r.Job{Arg1: 2, Arg2: 2, Valid: true}, ÷r.Job{Arg1: 2, Arg2: 0, Valid: true}, ÷r.Job{Arg1: 2, Arg2: 2, Valid: true}, }, Results: []*divider.JobResult{ ÷r.JobResult{ID: 0, Value: 1, Valid: true}, ÷r.JobResult{ID: 1, Value: 0, Valid: false}, ÷r.JobResult{ID: 2, Value: 1, Valid: true}, }, Err: nil, }
ProcessingError includes at least one job that will cause processing error.
Functions ¶
func NewJobProcessor ¶
func NewJobProcessor() *divider.JobProcessor
NewJobProcessor creates a new mocked JobProcessor.
func ProviderNonTerminalErrorTest ¶
func ProviderNonTerminalErrorTest(t *testing.T, provider divider.JobProvider)
ProviderNonTerminalErrorTest validates proper behaviour of JobProcessor on receiving NonTerminalError from JobProvider: it must not stop processing.
Specified JobProvider must return error of type divider.NonTerminalError.
func ProviderTerminalErrorTest ¶
func ProviderTerminalErrorTest(t *testing.T, provider divider.JobProvider)
ProviderTerminalErrorTest validates proper termination of JobProcessor on receiving TerminalError from JobProvider.
Specified JobProvider must return any error of eny type except divider.NonTerminalError error.
func RunTestCases ¶
RunTestCases runs provided testing function against mandatory test cases.
Types ¶
type BrokenWriter ¶
type BrokenWriter struct {
// contains filtered or unexported fields
}
BrokenWriter returns ErrBrokenWriter after n-th Write call.
func NewBrokenWriter ¶
func NewBrokenWriter(n int) *BrokenWriter
NewBrokenWriter creates a new BrokenWriter.
type FailFn ¶
type FailFn func() error
FailFn makes bad things.
func NewErrFailFn ¶
NewErrFailFn creates a new FailFn from error.
type Failer ¶
type Failer struct {
// contains filtered or unexported fields
}
Failer makes bad things happen.
type FakeJobProvider ¶
type FakeJobProvider struct { *Failer // contains filtered or unexported fields }
FakeJobProvider implements divider.JobProvider.
func NewFakeJobProvider ¶
func NewFakeJobProvider(jobs []*divider.Job) *FakeJobProvider
NewFakeJobProvider creates a new FakeJobProvider with io.Reader.
func (*FakeJobProvider) More ¶
func (f *FakeJobProvider) More() bool
More reports whether there is another element in the current array or object being parsed.
type FakeResultReporter ¶
type FakeResultReporter struct { *Failer // contains filtered or unexported fields }
FakeResultReporter copies processing results and can provide them with Results() call.
func NewFakeResultReporter ¶
func NewFakeResultReporter() *FakeResultReporter
NewFakeResultReporter creates a new FakeResultReporter.
func (*FakeResultReporter) Report ¶
func (f *FakeResultReporter) Report(result *divider.JobResult) (err error)
Report copies provided result.
func (*FakeResultReporter) Results ¶
func (f *FakeResultReporter) Results() []*divider.JobResult
Results returns previously saved results.