histmgr_helper_test.go 1.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Copyright IBM Corp. 2016 All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

		 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

17
package historydb
18
19
20
21

import (
	"testing"

22
	"github.com/hyperledger/fabric/common/ledger/testutil"
23
24
25
26
27
)

var strKeySep = string(compositeKeySep)

func TestConstructCompositeKey(t *testing.T) {
28
29
30
	compositeKey := ConstructCompositeHistoryKey("ns1", "key1", 1, 1)
	testutil.AssertNotNil(t, compositeKey)
	//historyleveldb_test.go tests the actual output
31
32
33
}

func TestConstructPartialCompositeKey(t *testing.T) {
34
35
	compositeStartKey := ConstructPartialCompositeHistoryKey("ns1", "key1", false)
	compositeEndKey := ConstructPartialCompositeHistoryKey("ns1", "key1", true)
36

37
38
	testutil.AssertEquals(t, compositeStartKey, []byte("ns1"+strKeySep+"key1"+strKeySep))
	testutil.AssertEquals(t, compositeEndKey, []byte("ns1"+strKeySep+"key1"+strKeySep+string([]byte{0xff})))
39
40
41
}

func TestSplitCompositeKey(t *testing.T) {
42
43
	compositeFullKey := []byte("ns1" + strKeySep + "key1" + strKeySep + "extra bytes to split")
	compositePartialKey := ConstructPartialCompositeHistoryKey("ns1", "key1", false)
44

45
46
47
	_, extraBytes := SplitCompositeHistoryKey(compositeFullKey, compositePartialKey)
	// second position should hold the extra bytes that were split off
	testutil.AssertEquals(t, extraBytes, []byte("extra bytes to split"))
48
}