github.com/iotexproject/iotex-core@v1.14.1-rc1/db/batch/writeinfo_test.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package batch
     7  
     8  import (
     9  	"bytes"
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestWriteInfo(t *testing.T) {
    17  	ns := "namespace"
    18  	key := []byte("key")
    19  	value := []byte("value")
    20  	ef := "fail to put %x"
    21  	wi := NewWriteInfo(Put, ns, key, value, fmt.Sprintf(ef, key))
    22  	require.Equal(t, ns, wi.Namespace())
    23  	require.Equal(t, Put, wi.WriteType())
    24  	require.True(t, bytes.Equal(key, wi.Key()))
    25  	require.True(t, bytes.Equal(value, wi.Value()))
    26  	require.Equal(t, fmt.Sprintf(ef, key), wi.Error())
    27  	require.True(t, bytes.Equal([]byte{110, 97, 109, 101, 115, 112, 97, 99, 101, 107, 101, 121, 118, 97, 108, 117, 101}, wi.SerializeWithoutWriteType()))
    28  	require.True(t, bytes.Equal([]byte{0, 110, 97, 109, 101, 115, 112, 97, 99, 101, 107, 101, 121, 118, 97, 108, 117, 101}, wi.Serialize()))
    29  }