-
Notifications
You must be signed in to change notification settings - Fork 662
/
test_subnet.go
50 lines (41 loc) · 1.3 KB
/
test_subnet.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import (
"testing"
"github.com/ava-labs/avalanchego/ids"
)
// SubnetTest is a test subnet
type SubnetTest struct {
T *testing.T
CantIsBootstrapped, CantBootstrapped bool
IsBootstrappedF func() bool
BootstrappedF func(ids.ID)
}
// Default set the default callable value to [cant]
func (s *SubnetTest) Default(cant bool) {
s.CantIsBootstrapped = cant
s.CantBootstrapped = cant
}
// IsBootstrapped calls IsBootstrappedF if it was initialized. If it wasn't
// initialized and this function shouldn't be called and testing was
// initialized, then testing will fail. Defaults to returning false.
func (s *SubnetTest) IsBootstrapped() bool {
if s.IsBootstrappedF != nil {
return s.IsBootstrappedF()
}
if s.CantIsBootstrapped && s.T != nil {
s.T.Fatalf("Unexpectedly called IsBootstrapped")
}
return false
}
// Bootstrapped calls BootstrappedF if it was initialized. If it wasn't
// initialized and this function shouldn't be called and testing was
// initialized, then testing will fail.
func (s *SubnetTest) Bootstrapped(chainID ids.ID) {
if s.BootstrappedF != nil {
s.BootstrappedF(chainID)
} else if s.CantBootstrapped && s.T != nil {
s.T.Fatalf("Unexpectedly called Bootstrapped")
}
}