|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2016 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package ledgerconfig |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/hyperledger/fabric/core/ledger/testutil" |
| 23 | + "github.com/spf13/viper" |
| 24 | +) |
| 25 | + |
| 26 | +func TestIsCouchDBEnabledDefault(t *testing.T) { |
| 27 | + setUpCoreYAMLConfig() |
| 28 | + defaultValue := IsCouchDBEnabled() |
| 29 | + testutil.AssertEquals(t, defaultValue, false) //test default config is false |
| 30 | +} |
| 31 | + |
| 32 | +func TestIsCouchDBEnabled(t *testing.T) { |
| 33 | + setUpCoreYAMLConfig() |
| 34 | + defer testutil.ResetConfigToDefaultValues() |
| 35 | + viper.Set("ledger.state.stateDatabase", "CouchDB") |
| 36 | + updatedValue := IsCouchDBEnabled() |
| 37 | + testutil.AssertEquals(t, updatedValue, true) //test config returns true |
| 38 | +} |
| 39 | + |
| 40 | +func TestGetCouchDBDefinition(t *testing.T) { |
| 41 | + setUpCoreYAMLConfig() |
| 42 | + defer testutil.ResetConfigToDefaultValues() |
| 43 | + viper.Set("ledger.state.stateDatabase", "CouchDB") |
| 44 | + couchDBDef := GetCouchDBDefinition() |
| 45 | + testutil.AssertEquals(t, couchDBDef.URL, "127.0.0.1:5984") |
| 46 | + testutil.AssertEquals(t, couchDBDef.Username, "") |
| 47 | + testutil.AssertEquals(t, couchDBDef.Password, "") |
| 48 | +} |
| 49 | + |
| 50 | +func TestIsHistoryDBEnabledDefault(t *testing.T) { |
| 51 | + setUpCoreYAMLConfig() |
| 52 | + defaultValue := IsHistoryDBEnabled() |
| 53 | + testutil.AssertEquals(t, defaultValue, false) //test default config is false |
| 54 | +} |
| 55 | + |
| 56 | +func TestIsHistoryDBEnabledWhenCouchDBIsDisabled(t *testing.T) { |
| 57 | + setUpCoreYAMLConfig() |
| 58 | + defer testutil.ResetConfigToDefaultValues() |
| 59 | + viper.Set("ledger.state.stateDatabase", "goleveldb") |
| 60 | + viper.Set("ledger.state.historyDatabase", true) |
| 61 | + updatedValue := IsHistoryDBEnabled() |
| 62 | + testutil.AssertEquals(t, updatedValue, false) //test config is false |
| 63 | +} |
| 64 | + |
| 65 | +func TestIsHistoryDBEnabledWhenOnlyCouchDBEnabled(t *testing.T) { |
| 66 | + setUpCoreYAMLConfig() |
| 67 | + defer testutil.ResetConfigToDefaultValues() |
| 68 | + viper.Set("ledger.state.stateDatabase", "CouchDB") |
| 69 | + viper.Set("ledger.state.historyDatabase", false) |
| 70 | + updatedValue := IsHistoryDBEnabled() |
| 71 | + testutil.AssertEquals(t, updatedValue, false) //test config is false |
| 72 | +} |
| 73 | + |
| 74 | +func TestIsHistoryDBEnabled(t *testing.T) { |
| 75 | + setUpCoreYAMLConfig() |
| 76 | + defer testutil.ResetConfigToDefaultValues() |
| 77 | + viper.Set("ledger.state.stateDatabase", "CouchDB") |
| 78 | + viper.Set("ledger.state.historyDatabase", true) |
| 79 | + updatedValue := IsHistoryDBEnabled() |
| 80 | + testutil.AssertEquals(t, updatedValue, true) //test config returns true |
| 81 | +} |
| 82 | + |
| 83 | +func setUpCoreYAMLConfig() { |
| 84 | + //call a helper method to load the core.yaml |
| 85 | + testutil.SetupCoreYAMLConfig("./../../../peer") |
| 86 | +} |
0 commit comments