github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/storage/mvcc/mvcc_test.go (about) 1 // Copyright 2022 zGraph Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mvcc 16 17 import ( 18 "reflect" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 ) 23 24 func TestLock_MarshalBinary(t *testing.T) { 25 lock := &Lock{ 26 StartVer: 100, 27 Primary: []byte("primary"), 28 Value: []byte("value"), 29 Op: Op_Lock, 30 TTL: 1000, 31 } 32 bytes, err := lock.MarshalBinary() 33 assert.Nil(t, err) 34 35 lock2 := &Lock{} 36 err = lock2.UnmarshalBinary(bytes) 37 assert.Nil(t, err) 38 39 assert.True(t, reflect.DeepEqual(lock, lock2)) 40 } 41 42 func TestValue_MarshalBinary(t *testing.T) { 43 value := &Value{ 44 Type: ValueTypeLock, 45 StartVer: 100, 46 CommitVer: 1001, 47 Value: []byte("value"), 48 } 49 bytes, err := value.MarshalBinary() 50 assert.Nil(t, err) 51 52 value2 := &Value{} 53 err = value2.UnmarshalBinary(bytes) 54 assert.Nil(t, err) 55 56 assert.True(t, reflect.DeepEqual(value, value2)) 57 }