github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/kbfsmd/merkle_leaf_test.go (about)

     1  // Copyright 2018 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package kbfsmd
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/keybase/client/go/kbfs/kbfscodec"
    11  	merkle "github.com/keybase/go-merkle-tree"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func testValueConstructor(t *testing.T, vc merkle.ValueConstructor) {
    16  	c := kbfscodec.NewMsgpack()
    17  
    18  	// Mimic the logic in merkle.Tree.findTyped.
    19  	data := []byte("hello world")
    20  	buf, err := c.Encode(data)
    21  	require.NoError(t, err)
    22  
    23  	obj := vc.Construct()
    24  	err = c.Decode(buf, &obj)
    25  	require.NoError(t, err)
    26  
    27  	require.Equal(t, &data, obj)
    28  }
    29  
    30  func TestConstructMerkleLeaf(t *testing.T) {
    31  	testValueConstructor(t, MerkleLeaf{})
    32  }
    33  
    34  func TestConstructEncryptedMerkleLeaf(t *testing.T) {
    35  	testValueConstructor(t, EncryptedMerkleLeaf{})
    36  }