forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
54 lines (45 loc) · 1.11 KB
/
status.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
package mock
import (
"context"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
// StatusMock returns the result specified by the Call
type StatusMock struct {
Call
}
var (
_ client.StatusClient = (*StatusMock)(nil)
_ client.StatusClient = (*StatusRecorder)(nil)
)
func (m *StatusMock) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
res, err := m.GetResponse(nil)
if err != nil {
return nil, err
}
return res.(*ctypes.ResultStatus), nil
}
// StatusRecorder can wrap another type (StatusMock, full client)
// and record the status calls
type StatusRecorder struct {
Client client.StatusClient
Calls []Call
}
func NewStatusRecorder(client client.StatusClient) *StatusRecorder {
return &StatusRecorder{
Client: client,
Calls: []Call{},
}
}
func (r *StatusRecorder) addCall(call Call) {
r.Calls = append(r.Calls, call)
}
func (r *StatusRecorder) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
res, err := r.Client.Status(ctx)
r.addCall(Call{
Name: "status",
Response: res,
Error: err,
})
return res, err
}