From f623c0ed89903413c6fd7cc8ab2d447f3d20ea36 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Thu, 29 Oct 2020 17:33:54 +1000 Subject: [PATCH] Add unit test for config flattening functions Signed-off-by: Ben Reedy --- config/flatten_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 config/flatten_test.go diff --git a/config/flatten_test.go b/config/flatten_test.go new file mode 100644 index 00000000..48d969fb --- /dev/null +++ b/config/flatten_test.go @@ -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) + } +}