-
Notifications
You must be signed in to change notification settings - Fork 672
/
test_bootstrapable.go
57 lines (46 loc) · 1.22 KB
/
test_bootstrapable.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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import (
"errors"
"testing"
"github.com/ava-labs/avalanchego/ids"
)
var (
_ Bootstrapable = &BootstrapableTest{}
errForceAccepted = errors.New("unexpectedly called ForceAccepted")
errClear = errors.New("unexpectedly called Clear")
)
// BootstrapableTest is a test engine that supports bootstrapping
type BootstrapableTest struct {
T *testing.T
CantForceAccepted, CantClear bool
ClearF func() error
ForceAcceptedF func(acceptedContainerIDs []ids.ID) error
}
// Default sets the default on call handling
func (b *BootstrapableTest) Default(cant bool) {
b.CantForceAccepted = cant
}
func (b *BootstrapableTest) Clear() error {
if b.ClearF != nil {
return b.ClearF()
} else if b.CantClear {
if b.T != nil {
b.T.Fatalf("Unexpectedly called Clear")
}
return errClear
}
return nil
}
func (b *BootstrapableTest) ForceAccepted(containerIDs []ids.ID) error {
if b.ForceAcceptedF != nil {
return b.ForceAcceptedF(containerIDs)
} else if b.CantForceAccepted {
if b.T != nil {
b.T.Fatalf("Unexpectedly called ForceAccepted")
}
return errForceAccepted
}
return nil
}