forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.go
59 lines (48 loc) · 1.52 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
54
55
56
57
58
59
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"
"github.com/stretchr/testify/mock"
)
// 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
ResultForInnerHash map[string]Result
}
// ResultByHash implements `txsub.ResultProvider`
func (results *MockResultProvider) ResultByHash(ctx context.Context, hash string) Result {
if r, ok := results.ResultForInnerHash[hash]; ok {
return r
}
if len(results.Results) > 0 {
r := results.Results[0]
results.Results = results.Results[1:]
return r
}
return Result{Err: ErrNoResults}
}
// MockSequenceProvider is a test helper that simplements the SequenceProvider
// interface
type MockSequenceProvider struct {
mock.Mock
}
// Get implements `txsub.SequenceProvider`
func (o *MockSequenceProvider) GetSequenceNumbers(addresses []string) (map[string]uint64, error) {
args := o.Called(addresses)
return args.Get(0).(map[string]uint64), args.Error(1)
}