github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/admin/commands/storage/read_seals_test.go (about)

     1  package storage
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/mock"
     9  	"github.com/stretchr/testify/require"
    10  	"gotest.tools/assert"
    11  
    12  	"github.com/onflow/flow-go/admin"
    13  	"github.com/onflow/flow-go/admin/commands"
    14  	"github.com/onflow/flow-go/model/flow"
    15  	protocolmock "github.com/onflow/flow-go/state/protocol/mock"
    16  	storagemock "github.com/onflow/flow-go/storage/mock"
    17  	"github.com/onflow/flow-go/utils/unittest"
    18  )
    19  
    20  func TestReadSealsByID(t *testing.T) {
    21  	t.Parallel()
    22  
    23  	state := new(protocolmock.State)
    24  	seals := new(storagemock.Seals)
    25  	index := new(storagemock.Index)
    26  
    27  	seal := unittest.Seal.Fixture()
    28  	seals.On("ByID", mock.AnythingOfType("flow.Identifier")).Return(
    29  		func(sealID flow.Identifier) *flow.Seal {
    30  			if sealID == seal.ID() {
    31  				return seal
    32  			}
    33  			return nil
    34  		},
    35  		func(sealID flow.Identifier) error {
    36  			if sealID == seal.ID() {
    37  				return nil
    38  			}
    39  			return fmt.Errorf("seal %#v not found", sealID)
    40  		},
    41  	)
    42  
    43  	command := NewReadSealsCommand(state, seals, index)
    44  
    45  	ctx, cancel := context.WithCancel(context.Background())
    46  	defer cancel()
    47  
    48  	req := &admin.CommandRequest{
    49  		Data: map[string]interface{}{
    50  			"seal": seal.ID().String(),
    51  		},
    52  	}
    53  	require.NoError(t, command.Validator(req))
    54  	result, err := command.Handler(ctx, req)
    55  	require.NoError(t, err)
    56  
    57  	resultMap, err := commands.ConvertToMap(seal)
    58  	require.NoError(t, err)
    59  
    60  	assert.DeepEqual(t, result, resultMap)
    61  }