-
Notifications
You must be signed in to change notification settings - Fork 661
/
test_storage.go
51 lines (42 loc) · 1018 Bytes
/
test_storage.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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"errors"
"testing"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/avalanche"
)
var (
errGet = errors.New("unexpectedly called Get")
errEdge = errors.New("unexpectedly called Edge")
_ Storage = &TestStorage{}
)
type TestStorage struct {
T *testing.T
CantGetVtx, CantEdge bool
GetVtxF func(ids.ID) (avalanche.Vertex, error)
EdgeF func() []ids.ID
}
func (s *TestStorage) Default(cant bool) {
s.CantGetVtx = cant
s.CantEdge = cant
}
func (s *TestStorage) GetVtx(id ids.ID) (avalanche.Vertex, error) {
if s.GetVtxF != nil {
return s.GetVtxF(id)
}
if s.CantGetVtx && s.T != nil {
s.T.Fatal(errGet)
}
return nil, errGet
}
func (s *TestStorage) Edge() []ids.ID {
if s.EdgeF != nil {
return s.EdgeF()
}
if s.CantEdge && s.T != nil {
s.T.Fatal(errEdge)
}
return nil
}