Skip to content

Commit 2605dda

Browse files
committed
[FAB-10104] Improve LedgerConfig UT coverage
This CR increases the UT coverage of core/ledger/ledgerconfig.go to 100% from 56% Change-Id: I027a48addbdca1b8b11e9bae9c63c70504fd42fb Signed-off-by: senthil <cendhu@gmail.com>
1 parent 9e9090e commit 2605dda

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

core/ledger/ledgerconfig/ledger_config_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func TestLedgerConfigPathDefault(t *testing.T) {
6363
testutil.AssertEquals(t,
6464
GetBlockStorePath(),
6565
"/var/hyperledger/production/ledgersData/chains")
66+
testutil.AssertEquals(t,
67+
GetPvtdataStorePath(),
68+
"/var/hyperledger/production/ledgersData/pvtdataStore")
69+
testutil.AssertEquals(t,
70+
GetInternalBookkeeperPath(),
71+
"/var/hyperledger/production/ledgersData/bookkeeper")
72+
6673
}
6774

6875
func TestLedgerConfigPath(t *testing.T) {
@@ -84,6 +91,12 @@ func TestLedgerConfigPath(t *testing.T) {
8491
testutil.AssertEquals(t,
8592
GetBlockStorePath(),
8693
"/tmp/hyperledger/production/ledgersData/chains")
94+
testutil.AssertEquals(t,
95+
GetPvtdataStorePath(),
96+
"/tmp/hyperledger/production/ledgersData/pvtdataStore")
97+
testutil.AssertEquals(t,
98+
GetInternalBookkeeperPath(),
99+
"/tmp/hyperledger/production/ledgersData/bookkeeper")
87100
}
88101

89102
func TestGetQueryLimitDefault(t *testing.T) {
@@ -106,6 +119,54 @@ func TestGetQueryLimit(t *testing.T) {
106119
testutil.AssertEquals(t, updatedValue, 5000) //test config returns 5000
107120
}
108121

122+
func TestMaxBatchUpdateSizeDefault(t *testing.T) {
123+
setUpCoreYAMLConfig()
124+
defaultValue := GetMaxBatchUpdateSize()
125+
testutil.AssertEquals(t, defaultValue, 1000) //test default config is 1000
126+
}
127+
128+
func TestMaxBatchUpdateSizeUnset(t *testing.T) {
129+
viper.Reset()
130+
defaultValue := GetMaxBatchUpdateSize()
131+
testutil.AssertEquals(t, defaultValue, 500) // 500 if maxBatchUpdateSize is not set
132+
}
133+
134+
func TestMaxBatchUpdateSize(t *testing.T) {
135+
setUpCoreYAMLConfig()
136+
defer ledgertestutil.ResetConfigToDefaultValues()
137+
viper.Set("ledger.state.couchDBConfig.maxBatchUpdateSize", 2000)
138+
updatedValue := GetMaxBatchUpdateSize()
139+
testutil.AssertEquals(t, updatedValue, 2000) //test config returns 2000
140+
}
141+
142+
func TestPvtdataStorePurgeIntervalDefault(t *testing.T) {
143+
setUpCoreYAMLConfig()
144+
defaultValue := GetPvtdataStorePurgeInterval()
145+
testutil.AssertEquals(t, defaultValue, uint64(100)) //test default config is 100
146+
}
147+
148+
func TestPvtdataStorePurgeIntervalUnset(t *testing.T) {
149+
viper.Reset()
150+
defaultValue := GetPvtdataStorePurgeInterval()
151+
testutil.AssertEquals(t, defaultValue, uint64(100)) // 100 if purgeInterval is not set
152+
}
153+
154+
func TestIsQueryReadHasingEnabled(t *testing.T) {
155+
testutil.AssertEquals(t, IsQueryReadsHashingEnabled(), true)
156+
}
157+
158+
func TestGetMaxDegreeQueryReadsHashing(t *testing.T) {
159+
testutil.AssertEquals(t, GetMaxDegreeQueryReadsHashing(), uint32(50))
160+
}
161+
162+
func TestPvtdataStorePurgeInterval(t *testing.T) {
163+
setUpCoreYAMLConfig()
164+
defer ledgertestutil.ResetConfigToDefaultValues()
165+
viper.Set("ledger.pvtdataStore.purgeInterval", 1000)
166+
updatedValue := GetPvtdataStorePurgeInterval()
167+
testutil.AssertEquals(t, updatedValue, uint64(1000)) //test config returns 1000
168+
}
169+
109170
func TestIsHistoryDBEnabledDefault(t *testing.T) {
110171
setUpCoreYAMLConfig()
111172
defaultValue := IsHistoryDBEnabled()
@@ -134,6 +195,12 @@ func TestIsAutoWarmIndexesEnabledDefault(t *testing.T) {
134195
testutil.AssertEquals(t, defaultValue, true) //test default config is true
135196
}
136197

198+
func TestIsAutoWarmIndexesEnabledUnset(t *testing.T) {
199+
viper.Reset()
200+
defaultValue := IsAutoWarmIndexesEnabled()
201+
testutil.AssertEquals(t, defaultValue, true) //test default config is true
202+
}
203+
137204
func TestIsAutoWarmIndexesEnabledTrue(t *testing.T) {
138205
setUpCoreYAMLConfig()
139206
defer ledgertestutil.ResetConfigToDefaultValues()
@@ -156,6 +223,12 @@ func TestGetWarmIndexesAfterNBlocksDefault(t *testing.T) {
156223
testutil.AssertEquals(t, defaultValue, 1) //test default config is true
157224
}
158225

226+
func TestGetWarmIndexesAfterNBlocksUnset(t *testing.T) {
227+
viper.Reset()
228+
defaultValue := GetWarmIndexesAfterNBlocks()
229+
testutil.AssertEquals(t, defaultValue, 1) //test default config is true
230+
}
231+
159232
func TestGetWarmIndexesAfterNBlocks(t *testing.T) {
160233
setUpCoreYAMLConfig()
161234
defer ledgertestutil.ResetConfigToDefaultValues()
@@ -164,6 +237,10 @@ func TestGetWarmIndexesAfterNBlocks(t *testing.T) {
164237
testutil.AssertEquals(t, updatedValue, 10)
165238
}
166239

240+
func TestGetMaxBlockfileSize(t *testing.T) {
241+
testutil.AssertEquals(t, GetMaxBlockfileSize(), 67108864)
242+
}
243+
167244
func setUpCoreYAMLConfig() {
168245
//call a helper method to load the core.yaml
169246
ledgertestutil.SetupCoreYAMLConfig()

0 commit comments

Comments
 (0)