ledger_config_test.go 2.79 KB
Newer Older
1
/*h
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.
*/

package ledgerconfig

import (
	"testing"

22
23
	"github.com/hyperledger/fabric/common/ledger/testutil"
	ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
24
25
26
27
28
	"github.com/spf13/viper"
)

func TestIsCouchDBEnabledDefault(t *testing.T) {
	setUpCoreYAMLConfig()
Mari Wade's avatar
Mari Wade committed
29
30
31
32
33
	// During a build the default values should be false.

	// If the  ledger test are run with CouchDb enabled, need to provide a mechanism
	// To let this test run but still test default values.
	if IsCouchDBEnabled() == true {
34
		ledgertestutil.ResetConfigToDefaultValues()
Mari Wade's avatar
Mari Wade committed
35
36
		defer viper.Set("ledger.state.stateDatabase", "CouchDB")
	}
37
38
39
40
41
42
	defaultValue := IsCouchDBEnabled()
	testutil.AssertEquals(t, defaultValue, false) //test default config is false
}

func TestIsCouchDBEnabled(t *testing.T) {
	setUpCoreYAMLConfig()
43
	defer ledgertestutil.ResetConfigToDefaultValues()
44
45
46
47
48
49
50
	viper.Set("ledger.state.stateDatabase", "CouchDB")
	updatedValue := IsCouchDBEnabled()
	testutil.AssertEquals(t, updatedValue, true) //test config returns true
}

func TestGetCouchDBDefinition(t *testing.T) {
	setUpCoreYAMLConfig()
51
	defer ledgertestutil.ResetConfigToDefaultValues()
52
53
54
55
56
57
58
59
60
61
62
63
64
	viper.Set("ledger.state.stateDatabase", "CouchDB")
	couchDBDef := GetCouchDBDefinition()
	testutil.AssertEquals(t, couchDBDef.URL, "127.0.0.1:5984")
	testutil.AssertEquals(t, couchDBDef.Username, "")
	testutil.AssertEquals(t, couchDBDef.Password, "")
}

func TestIsHistoryDBEnabledDefault(t *testing.T) {
	setUpCoreYAMLConfig()
	defaultValue := IsHistoryDBEnabled()
	testutil.AssertEquals(t, defaultValue, false) //test default config is false
}

65
func TestIsHistoryDBEnabledTrue(t *testing.T) {
66
	setUpCoreYAMLConfig()
67
	defer ledgertestutil.ResetConfigToDefaultValues()
68
69
	viper.Set("ledger.state.historyDatabase", true)
	updatedValue := IsHistoryDBEnabled()
70
	testutil.AssertEquals(t, updatedValue, true) //test config returns true
71
72
}

73
func TestIsHistoryDBEnabledFalse(t *testing.T) {
74
	setUpCoreYAMLConfig()
75
	defer ledgertestutil.ResetConfigToDefaultValues()
76
77
	viper.Set("ledger.state.historyDatabase", false)
	updatedValue := IsHistoryDBEnabled()
78
	testutil.AssertEquals(t, updatedValue, false) //test config returns false
79
80
81
82
}

func setUpCoreYAMLConfig() {
	//call a helper method to load the core.yaml
83
	ledgertestutil.SetupCoreYAMLConfig("./../../../peer")
84
}