/
test_helpers.go
53 lines (44 loc) · 1.35 KB
/
test_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package txsub
// This file provides mock implementations for the txsub interfaces
// which are useful in a testing context.
//
// NOTE: this file is not a test file so that other packages may import
// txsub and use these mocks in their own tests
import (
"context"
)
// MockSubmitter is a test helper that simplements the Submitter interface
type MockSubmitter struct {
R SubmissionResult
WasSubmittedTo bool
}
// Submit implements `txsub.Submitter`
func (sub *MockSubmitter) Submit(ctx context.Context, env string) SubmissionResult {
sub.WasSubmittedTo = true
return sub.R
}
// MockResultProvider is a test helper that simplements the ResultProvider
// interface
type MockResultProvider struct {
Results []Result
}
// ResultByHash implements `txsub.ResultProvider`
func (results *MockResultProvider) ResultByHash(ctx context.Context, hash string) (r Result) {
if len(results.Results) > 0 {
r = results.Results[0]
results.Results = results.Results[1:]
} else {
r = Result{Err: ErrNoResults}
}
return
}
// MockSequenceProvider is a test helper that simplements the SequenceProvider
// interface
type MockSequenceProvider struct {
Results map[string]uint64
Err error
}
// Get implements `txsub.SequenceProvider`
func (results *MockSequenceProvider) Get(addresses []string) (map[string]uint64, error) {
return results.Results, results.Err
}