github.com/KinWaiYuen/client-go/v2@v2.5.4/internal/mockstore/mocktikv/marshal_test.go (about) 1 // Copyright 2021 TiKV Authors 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 // NOTE: The code in this file is based on code from the 16 // TiDB project, licensed under the Apache License v 2.0 17 // 18 // https://github.com/pingcap/tidb/tree/cc5e161ac06827589c4966674597c137cc9e809c/store/tikv/mockstore/mocktikv/mock_tikv_test.go 19 // 20 21 // Copyright 2016 PingCAP, Inc. 22 // 23 // Licensed under the Apache License, Version 2.0 (the "License"); 24 // you may not use this file except in compliance with the License. 25 // You may obtain a copy of the License at 26 // 27 // http://www.apache.org/licenses/LICENSE-2.0 28 // 29 // Unless required by applicable law or agreed to in writing, software 30 // distributed under the License is distributed on an "AS IS" BASIS, 31 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 // See the License for the specific language governing permissions and 33 // limitations under the License. 34 35 package mocktikv 36 37 import ( 38 "testing" 39 40 "github.com/pingcap/kvproto/pkg/kvrpcpb" 41 "github.com/stretchr/testify/assert" 42 ) 43 44 func TestMarshalmvccLock(t *testing.T) { 45 assert := assert.New(t) 46 l := mvccLock{ 47 startTS: 47, 48 primary: []byte{'a', 'b', 'c'}, 49 value: []byte{'d', 'e'}, 50 op: kvrpcpb.Op_Put, 51 ttl: 444, 52 minCommitTS: 666, 53 } 54 bin, err := l.MarshalBinary() 55 assert.Nil(err) 56 57 var l1 mvccLock 58 err = l1.UnmarshalBinary(bin) 59 assert.Nil(err) 60 61 assert.Equal(l.startTS, l1.startTS) 62 assert.Equal(l.op, l1.op) 63 assert.Equal(l.ttl, l1.ttl) 64 assert.Equal(string(l.primary), string(l1.primary)) 65 assert.Equal(string(l.value), string(l1.value)) 66 assert.Equal(l.minCommitTS, l1.minCommitTS) 67 } 68 69 func TestMarshalmvccValue(t *testing.T) { 70 assert := assert.New(t) 71 v := mvccValue{ 72 valueType: typePut, 73 startTS: 42, 74 commitTS: 55, 75 value: []byte{'d', 'e'}, 76 } 77 bin, err := v.MarshalBinary() 78 assert.Nil(err) 79 80 var v1 mvccValue 81 err = v1.UnmarshalBinary(bin) 82 assert.Nil(err) 83 84 assert.Equal(v.valueType, v1.valueType) 85 assert.Equal(v.startTS, v1.startTS) 86 assert.Equal(v.commitTS, v1.commitTS) 87 assert.Equal(string(v.value), string(v.value)) 88 }