2018-01-13 14:41:49 +01:00
|
|
|
package cmd
|
2017-04-10 18:54:12 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-03-28 04:41:32 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-10 18:54:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadConfig(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2022-03-28 04:41:32 +02:00
|
|
|
require := require.New(t)
|
2017-04-10 18:54:12 +02:00
|
|
|
|
2018-01-13 14:41:49 +01:00
|
|
|
config, err := ReadConfigFile("../config_example.toml")
|
2022-03-28 04:41:32 +02:00
|
|
|
require.NoError(err)
|
|
|
|
require.NotNil(config)
|
2017-04-10 18:54:12 +02:00
|
|
|
|
|
|
|
assert.True(config.Respondd.Enable)
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.Equal("br-ffhb", config.Respondd.Interfaces[0].InterfaceName)
|
2017-04-10 18:54:12 +02:00
|
|
|
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)
|
|
|
|
|
2018-01-17 20:20:35 +01:00
|
|
|
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
|
2022-04-14 08:04:41 +02:00
|
|
|
assert.Len(config.Nodes.Output, 6)
|
2022-03-28 04:41:32 +02:00
|
|
|
outputs := config.Nodes.Output["meshviewer"].([]map[string]interface{})
|
2018-01-13 15:15:50 +01:00
|
|
|
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)
|
2017-10-12 15:25:00 +02:00
|
|
|
|
2018-01-13 14:41:49 +01:00
|
|
|
_, err = ReadConfigFile("testdata/config_invalid.toml")
|
2022-03-28 04:41:32 +02:00
|
|
|
assert.EqualError(err, "toml: line 2: expected '.' or '=', but got '\\n' instead")
|
2017-10-12 15:25:00 +02:00
|
|
|
|
|
|
|
_, err = ReadConfigFile("testdata/adsa.toml")
|
2022-03-28 04:41:32 +02:00
|
|
|
assert.EqualError(err, "open testdata/adsa.toml: no such file or directory")
|
2017-04-10 18:54:12 +02:00
|
|
|
}
|