Skip to content

Commit

Permalink
[FAB-3411] Improve UT coverage of ledgerconfig
Browse files Browse the repository at this point in the history
This patch adds unit tests for core/ledger/ledgerconfig.
The coverage will be improved from 27.8% to 83.3%.

Change-Id: I9f1b42518ab14eb5ea15f1bd6d51e33db8ae2f8f
Signed-off-by: Jun Nemoto <jun.nemoto.ff@hitachi.com>
  • Loading branch information
Jun Nemoto committed Jul 3, 2017
1 parent bdd4a96 commit 9da740a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions core/ledger/ledgerconfig/ledger_config_test.go
Expand Up @@ -46,6 +46,66 @@ func TestIsCouchDBEnabled(t *testing.T) {
testutil.AssertEquals(t, updatedValue, true) //test config returns true
}

func TestLedgerConfigPathDefault(t *testing.T) {
setUpCoreYAMLConfig()
testutil.AssertEquals(t,
GetRootPath(),
"/var/hyperledger/production/ledgersData")
testutil.AssertEquals(t,
GetLedgerProviderPath(),
"/var/hyperledger/production/ledgersData/ledgerProvider")
testutil.AssertEquals(t,
GetStateLevelDBPath(),
"/var/hyperledger/production/ledgersData/stateLeveldb")
testutil.AssertEquals(t,
GetHistoryLevelDBPath(),
"/var/hyperledger/production/ledgersData/historyLeveldb")
testutil.AssertEquals(t,
GetBlockStorePath(),
"/var/hyperledger/production/ledgersData/chains")
}

func TestLedgerConfigPath(t *testing.T) {
setUpCoreYAMLConfig()
defer ledgertestutil.ResetConfigToDefaultValues()
viper.Set("peer.fileSystemPath", "/tmp/hyperledger/production")
testutil.AssertEquals(t,
GetRootPath(),
"/tmp/hyperledger/production/ledgersData")
testutil.AssertEquals(t,
GetLedgerProviderPath(),
"/tmp/hyperledger/production/ledgersData/ledgerProvider")
testutil.AssertEquals(t,
GetStateLevelDBPath(),
"/tmp/hyperledger/production/ledgersData/stateLeveldb")
testutil.AssertEquals(t,
GetHistoryLevelDBPath(),
"/tmp/hyperledger/production/ledgersData/historyLeveldb")
testutil.AssertEquals(t,
GetBlockStorePath(),
"/tmp/hyperledger/production/ledgersData/chains")
}

func TestGetQueryLimitDefault(t *testing.T) {
setUpCoreYAMLConfig()
defaultValue := GetQueryLimit()
testutil.AssertEquals(t, defaultValue, 10000) //test default config is 10000
}

func TestGetQueryLimitUnset(t *testing.T) {
viper.Reset()
defaultValue := GetQueryLimit()
testutil.AssertEquals(t, defaultValue, 10000) //test default config is 10000
}

func TestGetQueryLimit(t *testing.T) {
setUpCoreYAMLConfig()
defer ledgertestutil.ResetConfigToDefaultValues()
viper.Set("ledger.state.couchDBConfig.queryLimit", 5000)
updatedValue := GetQueryLimit()
testutil.AssertEquals(t, updatedValue, 5000) //test config returns 5000
}

func TestIsHistoryDBEnabledDefault(t *testing.T) {
setUpCoreYAMLConfig()
defaultValue := IsHistoryDBEnabled()
Expand Down
2 changes: 2 additions & 0 deletions core/ledger/testutil/test_util.go
Expand Up @@ -89,8 +89,10 @@ func SetupCoreYAMLConfig() {
// ResetConfigToDefaultValues resets configurations optins back to defaults
func ResetConfigToDefaultValues() {
//reset to defaults
viper.Set("ledger.state.couchDBConfig.queryLimit", 10000)
viper.Set("ledger.state.stateDatabase", "goleveldb")
viper.Set("ledger.history.enableHistoryDatabase", false)
viper.Set("peer.fileSystemPath", "/var/hyperledger/production")
}

// SetLogLevel sets up log level
Expand Down

0 comments on commit 9da740a

Please sign in to comment.