github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/header/service_test.go (about)

     1  package header
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	libhead "github.com/celestiaorg/go-header"
    11  	"github.com/celestiaorg/go-header/sync"
    12  
    13  	"github.com/celestiaorg/celestia-node/header"
    14  )
    15  
    16  func TestGetByHeightHandlesError(t *testing.T) {
    17  	serv := Service{
    18  		syncer: &errorSyncer[*header.ExtendedHeader]{},
    19  	}
    20  
    21  	assert.NotPanics(t, func() {
    22  		h, err := serv.GetByHeight(context.Background(), 100)
    23  		assert.Error(t, err)
    24  		assert.Nil(t, h)
    25  	})
    26  }
    27  
    28  type errorSyncer[H libhead.Header[H]] struct{}
    29  
    30  func (d *errorSyncer[H]) Head(context.Context, ...libhead.HeadOption[H]) (H, error) {
    31  	var zero H
    32  	return zero, fmt.Errorf("dummy error")
    33  }
    34  
    35  func (d *errorSyncer[H]) State() sync.State {
    36  	return sync.State{}
    37  }
    38  
    39  func (d *errorSyncer[H]) SyncWait(context.Context) error {
    40  	return fmt.Errorf("dummy error")
    41  }