Skip to content

Commit

Permalink
disable bytes verification
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Elbehery <[email protected]>
  • Loading branch information
Elbehery committed Dec 14, 2023
1 parent c69e37f commit bb7a014
Showing 1 changed file with 47 additions and 19 deletions.
66 changes: 47 additions & 19 deletions movebucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,29 +296,51 @@ func TestBucket_MoveBucket(t *testing.T) {
name string
srcBucketPath []string
dstBucketPath []string
bucketToMove string
isInlined bool
expErr error
expActErr error
expAssertErr error
}{
{
name: "happy path",
srcBucketPath: []string{"x", "y", "z"},
dstBucketPath: []string{"a", "b"},
bucketToMove: "z",
isInlined: false,
expErr: nil,
expActErr: nil,
expAssertErr: nil,
},
{
name: "bucketToMove not exist in srcBucket",
srcBucketPath: []string{"x", "y"},
dstBucketPath: []string{"a", "b"},
bucketToMove: "z",
isInlined: false,
expActErr: berrors.ErrBucketNotFound,
expAssertErr: nil,
},
{
name: "bucketToMove exist in dstBucket",
srcBucketPath: []string{"x", "y", "z"},
dstBucketPath: []string{"a", "b", "z"},
bucketToMove: "z",
expActErr: berrors.ErrBucketExists,
expAssertErr: nil,
},
}

for _, tc := range testCases {

t.Run(tc.name, func(*testing.T) {
db := btesting.MustCreateDB(t)
var tmpFile string
//var tmpFile string

// arrange
if err := db.Update(func(tx *bolt.Tx) error {
bk := createBucketIfNotExist(t, tx, tc.srcBucketPath...)
insertRandKeysValuesBucket(t, bk, rand.Intn(4096))
createBucketIfNotExist(t, tx, tc.dstBucketPath...)
srcBK := createBucketIfNotExist(t, tx, tc.srcBucketPath...)
insertRandKeysValuesBucket(t, srcBK, rand.Intn(4096))
dstBK := createBucketIfNotExist(t, tx, tc.dstBucketPath...)
insertRandKeysValuesBucket(t, dstBK, rand.Intn(4096))

return nil
}); err != nil {
Expand All @@ -330,41 +352,47 @@ func TestBucket_MoveBucket(t *testing.T) {
if err := db.Update(func(tx *bolt.Tx) error {
srcBucket := retrieveParentBucket(t, tx, tc.srcBucketPath...)
dstBucket := retrieveChildBucket(t, tx, tc.dstBucketPath...)
bucketToMove := tc.srcBucketPath[len(tc.srcBucketPath)-1]

// dump db before moving the bucket for verification later
tmpFile = dumpDBToFile(t, tx)
//tmpFile = dumpDBToFile(t, tx)

mErr := srcBucket.MoveBucket([]byte(bucketToMove), dstBucket)
require.Equal(t, tc.expErr, mErr)
mErr := srcBucket.MoveBucket([]byte(tc.bucketToMove), dstBucket)
require.Equal(t, tc.expActErr, mErr)

return nil
}); err != nil {
t.Fatal(err)
}
db.MustCheck()

// skip assertion if failure expected
if tc.expActErr != nil {
return
}

// assert
if err := db.View(func(tx *bolt.Tx) error {
srcBucket := retrieveParentBucket(t, tx, tc.srcBucketPath...)
bucketToMove := tc.srcBucketPath[len(tc.srcBucketPath)-1]

if bk := srcBucket.Bucket([]byte(bucketToMove)); bk != nil {
t.Fatalf("expected childBucket %v to be moved from srcBucket %v", bucketToMove, srcBucket)
if bk := srcBucket.Bucket([]byte(tc.bucketToMove)); bk != nil {
t.Fatalf("expected childBucket %v to be moved from srcBucket %v", tc.bucketToMove, srcBucket)
}

dstBucket := retrieveChildBucket(t, tx, tc.dstBucketPath...)
if bk := dstBucket.Bucket([]byte(bucketToMove)); bk == nil {
t.Fatalf("expected childBucket %v to be child of dstBucket %v", bucketToMove, dstBucket)
if bk := dstBucket.Bucket([]byte(tc.bucketToMove)); bk == nil {
if tc.expAssertErr == berrors.ErrBucketNotFound {
return nil
}
t.Fatalf("expected childBucket %v to be child of dstBucket %v", tc.bucketToMove, dstBucket)
}

childBucket := dstBucket.Bucket([]byte(bucketToMove))
childBucket := dstBucket.Bucket([]byte(tc.bucketToMove))
if childBucket == nil {
t.Fatalf("expected childBucket %v to exist within dstBucket %v", bucketToMove, dstBucket)
t.Fatalf("expected childBucket %v to exist within dstBucket %v", tc.bucketToMove, dstBucket)
}

dbAsBytes := readDBFromFile(t, tmpFile)
require.Equal(t, dbAsBytes, encodeDBIntoBytes(t, tx))
//dbAsBytes := readDBFromFile(t, tmpFile)
//require.Equal(t, dbAsBytes, encodeDBIntoBytes(t, tx))

return nil
}); err != nil {
Expand Down

0 comments on commit bb7a014

Please sign in to comment.