2020-10-29 07:33:54 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2023-04-22 10:17:51 +00:00
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
2020-10-29 07:33:54 +00:00
|
|
|
)
|
|
|
|
|
2024-08-10 20:05:33 +00:00
|
|
|
// Unmarshal good configuration file and confirm data is flattened correctly.
|
2020-10-29 07:33:54 +00:00
|
|
|
func TestConfigFlattening(t *testing.T) {
|
2024-08-10 20:05:33 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-10-29 07:33:54 +00:00
|
|
|
goodYamlConfig := []byte(`---
|
|
|
|
|
|
|
|
collectors:
|
|
|
|
enabled: cpu,net,service
|
|
|
|
|
|
|
|
log:
|
|
|
|
level: debug`)
|
2024-09-10 22:34:10 +00:00
|
|
|
|
2020-10-29 07:33:54 +00:00
|
|
|
var data map[string]interface{}
|
2024-09-10 22:34:10 +00:00
|
|
|
|
2020-10-29 07:33:54 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|