-
Notifications
You must be signed in to change notification settings - Fork 672
/
test_bootstrap_tracker.go
64 lines (52 loc) · 1.8 KB
/
test_bootstrap_tracker.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
60
61
62
63
64
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/ava-labs/avalanchego/ids"
)
// BootstrapTrackerTest is a test subnet
type BootstrapTrackerTest struct {
T *testing.T
CantIsBootstrapped, CantBootstrapped, CantOnBootstrapCompleted bool
IsBootstrappedF func() bool
BootstrappedF func(ids.ID)
OnBootstrapCompletedF func() chan struct{}
}
// Default set the default callable value to [cant]
func (s *BootstrapTrackerTest) Default(cant bool) {
s.CantIsBootstrapped = cant
s.CantBootstrapped = cant
s.CantOnBootstrapCompleted = 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 *BootstrapTrackerTest) IsBootstrapped() bool {
if s.IsBootstrappedF != nil {
return s.IsBootstrappedF()
}
if s.CantIsBootstrapped && s.T != nil {
require.FailNow(s.T, "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 *BootstrapTrackerTest) Bootstrapped(chainID ids.ID) {
if s.BootstrappedF != nil {
s.BootstrappedF(chainID)
} else if s.CantBootstrapped && s.T != nil {
require.FailNow(s.T, "Unexpectedly called Bootstrapped")
}
}
func (s *BootstrapTrackerTest) OnBootstrapCompleted() chan struct{} {
if s.OnBootstrapCompletedF != nil {
return s.OnBootstrapCompletedF()
} else if s.CantOnBootstrapCompleted && s.T != nil {
require.FailNow(s.T, "Unexpectedly called OnBootstrapCompleted")
}
return nil
}