Add test for reading the config.yml
This commit is contained in:
parent
9352ef7f12
commit
b252274253
2
main.go
2
main.go
@ -30,7 +30,7 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&configFile, "config", "config.yml", "path of configuration file (default:config.yaml)")
|
flag.StringVar(&configFile, "config", "config.yml", "path of configuration file (default:config.yaml)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
config = models.ConfigReadFile(configFile)
|
config = models.ReadConfigFile(configFile)
|
||||||
nodes = models.NewNodes(config)
|
nodes = models.NewNodes(config)
|
||||||
|
|
||||||
if config.Influxdb.Enable {
|
if config.Influxdb.Enable {
|
||||||
|
@ -40,8 +40,8 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ConfigReadFile reads a Config models by path to a yml file
|
// reads a config models by path to a yml file
|
||||||
func ConfigReadFile(path string) *Config {
|
func ReadConfigFile(path string) *Config {
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
file, _ := ioutil.ReadFile(path)
|
file, _ := ioutil.ReadFile(path)
|
||||||
err := yaml.Unmarshal(file, &config)
|
err := yaml.Unmarshal(file, &config)
|
||||||
|
14
models/config_test.go
Normal file
14
models/config_test.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadConfig(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := ReadConfigFile("../config_example.yml")
|
||||||
|
assert.NotNil(config)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user