Add unit test for config flattening functions

Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
Ben Reedy 2020-10-29 17:33:54 +10:00 committed by Ben Reedy
parent ce5c6eed72
commit f623c0ed89

33
config/flatten_test.go Normal file
View File

@ -0,0 +1,33 @@
package config
import (
"gopkg.in/yaml.v2"
"reflect"
"testing"
)
// Unmarshal good configuration file and confirm data is flattened correctly
func TestConfigFlattening(t *testing.T) {
goodYamlConfig := []byte(`---
collectors:
enabled: cpu,net,service
log:
level: debug`)
var data map[string]interface{}
err := yaml.Unmarshal(goodYamlConfig, &data)
if err != nil {
t.Error(err)
}
expectedResult := map[string]string{
"collectors.enabled": "cpu,net,service",
"log.level": "debug",
}
flattenedValues := flatten(data)
if !reflect.DeepEqual(expectedResult, flattenedValues) {
t.Errorf("Flattened values do not match!\nExpected result: %s\nActual result: %s", expectedResult, flattenedValues)
}
}