Skip to content

Commit

Permalink
Added more snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeless committed Jul 24, 2020
1 parent 0b26536 commit 562f9de
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@ package snapshot
import (
"fmt"
"io"
"path/filepath"
"strings"
"testing"

"go.uber.org/zap"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSnapshotRead(t *testing.T) {
logger, _ := zap.NewDevelopment()
tests := []struct {
name string
input string
expect string
name string
testFile string
input string
expect string
}{
{
name: "name",
input: "input",
expect: "expect",
},
//{name: "name", testFile: "eos-local_jdev_0000000638-0000027ebcabc3da56aa3c50b76d6ea2b85e0b9ac7c737be7d3e0a8ecc162d8d-snapshot.bin", input: "input", expect: "expect"},/**/
{name: "name", testFile: "eos-dev1_ondemand-ffbc-states_0004841949-0049e1ddbc5bdecd37887da27115b65fa9c10b03c802efc0b0a78aece17b236e-snapshot.bin", input: "input", expect: "expect"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
filename := "/tmp/0125111385-07750c59b24ed52d2dbf2048b67b58e9c9bd53ff5cc4550277718c1d5d800f73-snapshot.bin" // mainnet
//filename := "/tmp/0003212331-0031042b02b2cf711fee6e1e24da94101fa6c1ea9ece568d5f13232473429db1-snapshot.bin" // kylin
r, err := NewReader(filename)
fmt.Println("Filename", filename)
testFile := testData(test.testFile)
r, err := NewReader(testFile)
require.NoError(t, err)
defer r.Close()

assert.NoError(t, err)
Expand All @@ -40,23 +41,40 @@ func TestSnapshotRead(t *testing.T) {
break
}
assert.NoError(t, err)
fmt.Println("Section", section.Name, "rows", section.RowCount, "bytes", section.BufferSize, "offset", section.Offset)

if strings.Contains(section.Name, "contract") {
logger.Info("new section",
zap.String("section_name", section.Name),
zap.Uint64("row_count", section.RowCount),
zap.Uint64("bytes_count", section.BufferSize),
zap.Uint64("bytes_count", section.Offset),
)
if strings.Contains(section.Name, "") {
require.NoError(t, section.Process(func(o interface{}) error {
switch obj := o.(type) {
case *TableIDObject:
fmt.Println("Table ID", obj.Code, obj.Scope, obj.TableName)
logger.Info("Table ID", zap.Reflect("table_id", obj))
case *KeyValueObject:
fmt.Println("KV", obj.PrimKey, obj.Value)
logger.Info("Key Value Object", zap.Reflect("kv", obj))
case *Index64Object:
logger.Info("Index64Object", zap.Reflect("index_64_object", obj))
case *Index128Object:
logger.Info("Index128Object", zap.Reflect("index_128_object", obj))
case *Index256Object:
logger.Info("Index256Object", zap.Reflect("index_256_object", obj))
case *IndexDoubleObject:
logger.Info("IndexDoubleObject", zap.Reflect("index_double_object", obj))
case *IndexLongDoubleObject:
logger.Info("IndexLongDoubleObject", zap.Reflect("index_long_object", obj))
default:
fmt.Printf("Ignoring row %T\n", obj)
}
return nil

}))
}
}
})
}
}

func testData(filename string) string {
return filepath.Join("test-data", filename)
}
Binary file not shown.
Binary file not shown.

0 comments on commit 562f9de

Please sign in to comment.