-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_test.go
42 lines (34 loc) · 989 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"strings"
"testing"
)
func TestOverride(t *testing.T) {
cases, err := os.ReadDir("./testCases")
require.NoError(t, err)
for _, inputFile := range cases {
if strings.Contains(inputFile.Name(), ".input.") {
expectedPath := "./testCases/" + strings.Replace(inputFile.Name(), ".input", ".expected", 1)
t.Run(strings.Replace(inputFile.Name(), ".input.yml", "", 1), func(t *testing.T) {
file, err := loadAlertFile("./testCases/" + inputFile.Name())
require.NoError(t, err)
for _, group := range file.Groups {
for _, rule := range group.Rules {
if len(rule.OverrideRules) > 0 {
file.Override(*rule)
}
}
}
output := file.Exporter()
expectedFile, err := os.Open(expectedPath)
require.NoError(t, err)
expected, err := ioutil.ReadAll(expectedFile)
require.NoError(t, err)
require.Equal(t, string(expected), output)
})
}
}
}