2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
package config_test
|
|
|
|
|
|
|
|
import (
|
2018-03-22 14:13:57 +00:00
|
|
|
"bytes"
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/spf13/viper"
|
2017-11-02 22:37:27 +00:00
|
|
|
)
|
|
|
|
|
2018-03-22 14:13:57 +00:00
|
|
|
var vulcanizeConfig = []byte(`
|
|
|
|
[database]
|
|
|
|
name = "dbname"
|
|
|
|
hostname = "localhost"
|
|
|
|
port = 5432
|
|
|
|
|
|
|
|
[client]
|
|
|
|
ipcPath = "IPCPATH/geth.ipc"
|
|
|
|
`)
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
var _ = Describe("Loading the config", func() {
|
|
|
|
|
|
|
|
It("reads the private config using the environment", func() {
|
2018-03-22 14:13:57 +00:00
|
|
|
viper.SetConfigName("config")
|
2020-05-30 03:02:47 +00:00
|
|
|
viper.AddConfigPath("$GOPATH/src/github.com/vulcanize/ipfs-chain-watcher/environments/")
|
2018-02-13 16:31:57 +00:00
|
|
|
Expect(viper.Get("client.ipcpath")).To(BeNil())
|
2018-03-22 14:13:57 +00:00
|
|
|
|
|
|
|
testConfig := viper.New()
|
|
|
|
testConfig.SetConfigType("toml")
|
|
|
|
err := testConfig.ReadConfig(bytes.NewBuffer(vulcanizeConfig))
|
2017-12-11 21:08:00 +00:00
|
|
|
Expect(err).To(BeNil())
|
2018-02-13 16:31:57 +00:00
|
|
|
Expect(testConfig.Get("database.hostname")).To(Equal("localhost"))
|
2018-03-22 14:13:57 +00:00
|
|
|
Expect(testConfig.Get("database.name")).To(Equal("dbname"))
|
2018-02-13 16:31:57 +00:00
|
|
|
Expect(testConfig.Get("database.port")).To(Equal(int64(5432)))
|
2018-03-22 14:13:57 +00:00
|
|
|
Expect(testConfig.Get("client.ipcpath")).To(Equal("IPCPATH/geth.ipc"))
|
2017-12-11 21:08:00 +00:00
|
|
|
})
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
})
|