From b2522742535e6f186765930a5177c960dac32e02 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sun, 20 Mar 2016 19:54:43 +0100 Subject: [PATCH] Add test for reading the config.yml --- config_example.yaml => config_example.yml | 0 main.go | 2 +- models/config.go | 4 ++-- models/config_test.go | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) rename config_example.yaml => config_example.yml (100%) create mode 100644 models/config_test.go diff --git a/config_example.yaml b/config_example.yml similarity index 100% rename from config_example.yaml rename to config_example.yml diff --git a/main.go b/main.go index 884d1a8..1989d01 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ var ( func main() { flag.StringVar(&configFile, "config", "config.yml", "path of configuration file (default:config.yaml)") flag.Parse() - config = models.ConfigReadFile(configFile) + config = models.ReadConfigFile(configFile) nodes = models.NewNodes(config) if config.Influxdb.Enable { diff --git a/models/config.go b/models/config.go index 0f35088..17c0e89 100644 --- a/models/config.go +++ b/models/config.go @@ -40,8 +40,8 @@ type Config struct { } } -//ConfigReadFile reads a Config models by path to a yml file -func ConfigReadFile(path string) *Config { +// reads a config models by path to a yml file +func ReadConfigFile(path string) *Config { config := &Config{} file, _ := ioutil.ReadFile(path) err := yaml.Unmarshal(file, &config) diff --git a/models/config_test.go b/models/config_test.go new file mode 100644 index 0000000..c78a4ab --- /dev/null +++ b/models/config_test.go @@ -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) +}