github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/avalanche/bootstrap/queue/test_parser.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package queue 5 6 import ( 7 "context" 8 "errors" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 ) 13 14 var errParse = errors.New("unexpectedly called Parse") 15 16 // TestParser is a test Parser 17 type TestParser struct { 18 T *testing.T 19 20 CantParse bool 21 22 ParseF func(context.Context, []byte) (Job, error) 23 } 24 25 func (p *TestParser) Default(cant bool) { 26 p.CantParse = cant 27 } 28 29 func (p *TestParser) Parse(ctx context.Context, b []byte) (Job, error) { 30 if p.ParseF != nil { 31 return p.ParseF(ctx, b) 32 } 33 if p.CantParse && p.T != nil { 34 require.FailNow(p.T, errParse.Error()) 35 } 36 return nil, errParse 37 }