Skip to content

Commit

Permalink
fix bucket_meta_test/entry_test
Browse files Browse the repository at this point in the history
  • Loading branch information
gphper committed Apr 20, 2022
1 parent ed7a26d commit d1cb03c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions bucket_meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

type BucketTestSuite struct {
suite.Suite
bucketMeat *BucketMeta
exceptEncode []byte
tempFile string
bucketMeat *BucketMeta
expectedEncode []byte
tempFile string
}

func (suite *BucketTestSuite) SetupSuite() {
Expand All @@ -38,14 +38,14 @@ func (suite *BucketTestSuite) SetupSuite() {
startSize: 6,
endSize: 6,
}
suite.exceptEncode = []byte{51, 34, 113, 225, 6, 0, 0, 0, 6, 0, 0, 0, 107, 101, 121, 49, 48, 48, 107, 101, 121, 57, 57, 57}
suite.expectedEncode = []byte{51, 34, 113, 225, 6, 0, 0, 0, 6, 0, 0, 0, 107, 101, 121, 49, 48, 48, 107, 101, 121, 57, 57, 57}
suite.tempFile = "/tmp/metadata.meta"
fd, err := os.OpenFile(filepath.Clean(suite.tempFile), os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
require.Failf(suite.T(), "init file fail", err.Error())
}

_, err = fd.WriteAt(suite.exceptEncode, 0)
_, err = fd.WriteAt(suite.expectedEncode, 0)
if err != nil {
require.Failf(suite.T(), "write data to file fail", err.Error())
}
Expand All @@ -54,7 +54,7 @@ func (suite *BucketTestSuite) SetupSuite() {

func (suite *BucketTestSuite) TestEncode() {
encodeValue := suite.bucketMeat.Encode()
assert.Equal(suite.T(), suite.exceptEncode, encodeValue)
assert.Equal(suite.T(), suite.expectedEncode, encodeValue)
}

func (suite *BucketTestSuite) TestReadBucketMeta() {
Expand Down
12 changes: 6 additions & 6 deletions entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

type EntryTestSuite struct {
suite.Suite
entry Entry
expectEncode []byte
entry Entry
expectedEncode []byte
}

func (suite *EntryTestSuite) SetupSuite() {
Expand All @@ -44,11 +44,11 @@ func (suite *EntryTestSuite) SetupSuite() {
},
position: 0,
}
suite.expectEncode = []byte{48, 176, 185, 16, 1, 38, 64, 92, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 101, 115, 116, 95, 101, 110, 116, 114, 121, 107, 101, 121, 95, 48, 48, 48, 49, 118, 97, 108, 95, 48, 48, 48, 49}
suite.expectedEncode = []byte{48, 176, 185, 16, 1, 38, 64, 92, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 101, 115, 116, 95, 101, 110, 116, 114, 121, 107, 101, 121, 95, 48, 48, 48, 49, 118, 97, 108, 95, 48, 48, 48, 49}
}

func (suite *EntryTestSuite) TestEncode() {
ok := reflect.DeepEqual(suite.entry.Encode(), suite.expectEncode)
ok := reflect.DeepEqual(suite.entry.Encode(), suite.expectedEncode)
assert.True(suite.T(), ok, "entry's encode test fail")
}

Expand All @@ -62,8 +62,8 @@ func (suite *EntryTestSuite) TestIsZero() {

func (suite *EntryTestSuite) TestGetCrc() {

crc1 := suite.entry.GetCrc(suite.expectEncode[:42])
crc2 := binary.LittleEndian.Uint32(suite.expectEncode[:4])
crc1 := suite.entry.GetCrc(suite.expectedEncode[:42])
crc2 := binary.LittleEndian.Uint32(suite.expectedEncode[:4])

if crc1 != crc2 {
assert.Fail(suite.T(), "entry's GetCrc test fail")
Expand Down

0 comments on commit d1cb03c

Please sign in to comment.