mirror of
https://github.com/prometheus-community/windows_exporter
synced 2025-01-04 21:40:09 +00:00
0711268d3c
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
35 lines
748 B
Go
35 lines
748 B
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
}
|