Skip to content

Commit

Permalink
[FAB-3412] Increase coverage for ledger/ledgermgmt
Browse files Browse the repository at this point in the history
This CR increases coverage from 71% to 93%.

Change-Id: Ie3f7e19beb64c87da20c73d2771de7aa99ac177f
Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu committed May 4, 2017
1 parent 1dfdee5 commit 645256f
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions core/ledger/ledgermgmt/ledger_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,46 @@ func TestMain(m *testing.M) {
}

func TestLedgerMgmt(t *testing.T) {
// Check for error when creating/opening ledger without initialization.
gb, _ := test.MakeGenesisBlock(constructTestLedgerID(0))
l, err := CreateLedger(gb)
testutil.AssertNil(t, l)
testutil.AssertEquals(t, err, ErrLedgerMgmtNotInitialized)

ledgerID := constructTestLedgerID(2)
l, err = OpenLedger(ledgerID)
testutil.AssertNil(t, l)
testutil.AssertEquals(t, err, ErrLedgerMgmtNotInitialized)

ids, err := GetLedgerIDs()
testutil.AssertNil(t, ids)
testutil.AssertEquals(t, err, ErrLedgerMgmtNotInitialized)

Close()

InitializeTestEnv()
defer CleanupTestEnv()

numLedgers := 10
ledgers := make([]ledger.PeerLedger, 10)
ledgers := make([]ledger.PeerLedger, numLedgers)
for i := 0; i < numLedgers; i++ {
gb, _ := test.MakeGenesisBlock(constructTestLedgerID(i))
l, _ := CreateLedger(gb)
ledgers[i] = l
}

ledgerID := constructTestLedgerID(2)
ids, _ = GetLedgerIDs()
testutil.AssertEquals(t, len(ids), numLedgers)
for i := 0; i < numLedgers; i++ {
testutil.AssertEquals(t, ids[i], constructTestLedgerID(i))
}

ledgerID = constructTestLedgerID(2)
t.Logf("Ledger selected for test = %s", ledgerID)
_, err := OpenLedger(ledgerID)
_, err = OpenLedger(ledgerID)
testutil.AssertEquals(t, err, ErrLedgerAlreadyOpened)

l := ledgers[2]
l = ledgers[2]
l.Close()
l, err = OpenLedger(ledgerID)
testutil.AssertNoError(t, err, "")
Expand All @@ -60,8 +83,9 @@ func TestLedgerMgmt(t *testing.T) {

// close all opened ledgers and ledger mgmt
Close()

// Restart ledger mgmt with existing ledgers
initialize()
Initialize()
l, err = OpenLedger(ledgerID)
testutil.AssertNoError(t, err, "")
Close()
Expand Down

0 comments on commit 645256f

Please sign in to comment.