yanic/cmd/config_test.go

53 lines
1.5 KiB
Go
Raw Permalink Normal View History

2018-01-13 14:41:49 +01:00
package cmd
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestReadConfig(t *testing.T) {
assert := assert.New(t)
2019-01-24 02:54:21 +01:00
config := &ServeConfig{}
err := ReadConfigFile("../config_example.toml", config)
2018-01-13 14:41:49 +01:00
assert.NoError(err)
assert.NotNil(config)
assert.True(config.Respondd.Enable)
assert.Equal("br-ffhb", config.Respondd.Interfaces[0].InterfaceName)
assert.Equal(time.Minute, config.Respondd.CollectInterval.Duration)
assert.Equal(time.Hour*24*7, config.Nodes.PruneAfter.Duration)
assert.Equal(time.Hour*24*7, config.Database.DeleteAfter.Duration)
assert.Len(config.Respondd.Sites, 1)
assert.Contains(config.Respondd.Sites, "ffhb")
assert.Contains(config.Respondd.Sites["ffhb"].Domains, "city")
2018-01-13 15:15:50 +01:00
// Test output plugins
2020-01-05 16:56:01 +01:00
assert.Len(config.Nodes.Output, 5)
2018-01-13 15:15:50 +01:00
outputs := config.Nodes.Output["meshviewer"].([]interface{})
assert.Len(outputs, 1)
meshviewer := outputs[0]
assert.EqualValues(map[string]interface{}{
"version": int64(2),
"enable": false,
"nodes_path": "/var/www/html/meshviewer/data/nodes.json",
"graph_path": "/var/www/html/meshviewer/data/graph.json",
2018-01-13 19:08:46 +01:00
"filter": map[string]interface{}{
"no_owner": true,
},
2018-01-13 15:15:50 +01:00
}, meshviewer)
2019-01-24 02:54:21 +01:00
err = ReadConfigFile("testdata/config_invalid.toml", config)
assert.Error(err, "not unmarshalable")
2018-01-13 15:15:50 +01:00
assert.Contains(err.Error(), "invalid TOML syntax")
2019-01-24 02:54:21 +01:00
err = ReadConfigFile("testdata/adsa.toml", config)
assert.Error(err, "not found able")
assert.Contains(err.Error(), "no such file or directory")
}