github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/common/test_bootstrapper.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package common 5 6 import ( 7 "context" 8 "errors" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 var ( 14 _ BootstrapableEngine = (*BootstrapperTest)(nil) 15 16 errClear = errors.New("unexpectedly called Clear") 17 ) 18 19 type BootstrapperTest struct { 20 EngineTest 21 22 CantClear bool 23 24 ClearF func(ctx context.Context) error 25 } 26 27 func (b *BootstrapperTest) Default(cant bool) { 28 b.EngineTest.Default(cant) 29 30 b.CantClear = cant 31 } 32 33 func (b *BootstrapperTest) Clear(ctx context.Context) error { 34 if b.ClearF != nil { 35 return b.ClearF(ctx) 36 } 37 if b.CantClear && b.T != nil { 38 require.FailNow(b.T, errClear.Error()) 39 } 40 return errClear 41 }