forked from cerc-io/ipld-eth-server
Update functions that return error to not return pointer
* Matches Golang convention
This commit is contained in:
@@ -24,12 +24,12 @@ var NewErrConfigFileNotFound = func(environment string) error {
|
||||
return errors.New(fmt.Sprintf("No configuration found for environment: %v", environment))
|
||||
}
|
||||
|
||||
func NewConfig(environment string) (*Config, error) {
|
||||
func NewConfig(environment string) (Config, error) {
|
||||
filenameWithExtension := fmt.Sprintf("%s.toml", environment)
|
||||
absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension)
|
||||
config, err := parseConfigFile(absolutePath)
|
||||
if err != nil {
|
||||
return nil, NewErrConfigFileNotFound(environment)
|
||||
return Config{}, NewErrConfigFileNotFound(environment)
|
||||
} else {
|
||||
if !filepath.IsAbs(config.Client.IPCPath) {
|
||||
config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath)
|
||||
@@ -43,16 +43,16 @@ func ProjectRoot() string {
|
||||
return path.Join(path.Dir(filename), "..", "..")
|
||||
}
|
||||
|
||||
func parseConfigFile(filePath string) (*Config, error) {
|
||||
func parseConfigFile(filePath string) (Config, error) {
|
||||
var cfg Config
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return Config{}, err
|
||||
} else {
|
||||
_, err := toml.DecodeFile(filePath, &cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return Config{}, err
|
||||
}
|
||||
return &cfg, err
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package config_test
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/pkg/config"
|
||||
cfg "github.com/8thlight/vulcanizedb/pkg/config"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -11,20 +11,20 @@ import (
|
||||
var _ = Describe("Loading the config", func() {
|
||||
|
||||
It("reads the private config using the environment", func() {
|
||||
privateConfig, err := config.NewConfig("private")
|
||||
privateConfig, err := cfg.NewConfig("private")
|
||||
|
||||
Expect(err).To(BeNil())
|
||||
Expect(privateConfig.Database.Hostname).To(Equal("localhost"))
|
||||
Expect(privateConfig.Database.Name).To(Equal("vulcanize_private"))
|
||||
Expect(privateConfig.Database.Port).To(Equal(5432))
|
||||
expandedPath := filepath.Join(config.ProjectRoot(), "test_data_dir/geth.ipc")
|
||||
expandedPath := filepath.Join(cfg.ProjectRoot(), "test_data_dir/geth.ipc")
|
||||
Expect(privateConfig.Client.IPCPath).To(Equal(expandedPath))
|
||||
})
|
||||
|
||||
It("returns an error when there is no matching config file", func() {
|
||||
config, err := config.NewConfig("bad-config")
|
||||
config, err := cfg.NewConfig("bad-config")
|
||||
|
||||
Expect(config).To(BeNil())
|
||||
Expect(config).To(Equal(cfg.Config{}))
|
||||
Expect(err).NotTo(BeNil())
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user