Alerting: Fix unmarshalling of GettableStatus to include time intervals (#112602)
* move test files into test-data * add test for the bug * populate time-intervals of gettableStatus config
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package definitions
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -15,6 +17,32 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
//go:embed test-data/*.*
|
||||
var testData embed.FS
|
||||
|
||||
func Test_GettableStatusUnmarshalJSON(t *testing.T) {
|
||||
incoming, err := testData.ReadFile(path.Join("test-data", "gettable-status.json"))
|
||||
require.Nil(t, err)
|
||||
|
||||
var actual GettableStatus
|
||||
require.NoError(t, json.Unmarshal(incoming, &actual))
|
||||
|
||||
actualJson, err := json.Marshal(actual)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected, err := testData.ReadFile(path.Join("test-data", "gettable-status-expected.json"))
|
||||
require.NoError(t, err)
|
||||
assert.JSONEq(t, string(expected), string(actualJson))
|
||||
|
||||
v := reflect.ValueOf(actual.Config.Config)
|
||||
ty := v.Type()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
field := v.Field(i)
|
||||
fieldName := ty.Field(i).Name
|
||||
assert.False(t, field.IsZero(), "Field %s should not be zero value", fieldName)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_GettableUserConfigUnmarshaling(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
desc, input string
|
||||
@@ -140,10 +168,10 @@ alertmanager_config: |
|
||||
func Test_GettableUserConfigRoundtrip(t *testing.T) {
|
||||
// raw contains secret fields. We'll unmarshal, re-marshal, and ensure
|
||||
// the fields are not redacted.
|
||||
yamlEncoded, err := os.ReadFile("alertmanager_test_artifact.yaml")
|
||||
yamlEncoded, err := testData.ReadFile(path.Join("test-data", "alertmanager_test_artifact.yaml"))
|
||||
require.Nil(t, err)
|
||||
|
||||
jsonEncoded, err := os.ReadFile("alertmanager_test_artifact.json")
|
||||
jsonEncoded, err := testData.ReadFile(path.Join("test-data", "alertmanager_test_artifact.json"))
|
||||
require.Nil(t, err)
|
||||
|
||||
// test GettableUserConfig (yamlDecode -> jsonEncode)
|
||||
@@ -162,7 +190,7 @@ func Test_GettableUserConfigRoundtrip(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Marshaling_Validation(t *testing.T) {
|
||||
jsonEncoded, err := os.ReadFile("alertmanager_test_artifact.json")
|
||||
jsonEncoded, err := testData.ReadFile(path.Join("test-data", "alertmanager_test_artifact.json"))
|
||||
require.Nil(t, err)
|
||||
|
||||
var tmp GettableUserConfig
|
||||
|
||||
Reference in New Issue
Block a user