Skip to content

Commit

Permalink
[FAB-3413] Increase coverage for core/ledger/util
Browse files Browse the repository at this point in the history
This CR increases coverage for util.go and txvalidationflag.go
to 100%. Will remove filterbitarray.go and filterbitarray_test.go
in a separate CR as these files are not being used.

Change-Id: I2a6c9d97af0a4674a3b6a019da3a93f0a01468fb
Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu committed May 4, 2017
1 parent 1dfdee5 commit 347e995
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions core/ledger/util/txvalidationflags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright IBM Corp. 2017 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.
*/

package util

import (
"testing"

"github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
)

func TestTransactionValidationFlags(t *testing.T) {
txFlags := NewTxValidationFlags(10)
assert.Equal(t, 10, len(txFlags))

txFlags.SetFlag(0, peer.TxValidationCode_VALID)
assert.Equal(t, peer.TxValidationCode_VALID, txFlags.Flag(0))
assert.Equal(t, true, txFlags.IsValid(0))

txFlags.SetFlag(1, peer.TxValidationCode_MVCC_READ_CONFLICT)
assert.Equal(t, true, txFlags.IsInvalid(1))
}
34 changes: 34 additions & 0 deletions core/ledger/util/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright IBM Corp. 2017 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.
*/

package util

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetSortedKeys(t *testing.T) {
mapKeyValue := make(map[string]int)
mapKeyValue["blue"] = 10
mapKeyValue["apple"] = 15
mapKeyValue["red"] = 12
mapKeyValue["123"] = 22
mapKeyValue["a"] = 33
mapKeyValue[""] = 30
assert.Equal(t, []string{"", "123", "a", "apple", "blue", "red"}, GetSortedKeys(mapKeyValue))
}

0 comments on commit 347e995

Please sign in to comment.