mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-08 18:08:59 +08:00
fix(alertmanager): fix tests for alertmanager (#7225)
This commit is contained in:
parent
b1e3f03bb5
commit
4177b88a4e
@ -2,12 +2,14 @@ package alertmanagertypes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/alertmanager/config"
|
"github.com/prometheus/alertmanager/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateRuleIDMatcher(t *testing.T) {
|
func TestCreateRuleIDMatcher(t *testing.T) {
|
||||||
@ -111,12 +113,15 @@ func TestCreateRuleIDMatcher(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes, err := json.Marshal(cfg.alertmanagerConfig.Route.Routes)
|
actualRoutes, err := json.Marshal(cfg.alertmanagerConfig.Route.Routes)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var actualRoutes []map[string]any
|
expectedRoutes, err := json.Marshal(tc.expectedRoutes)
|
||||||
err = json.Unmarshal(routes, &actualRoutes)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.ElementsMatch(t, tc.expectedRoutes, actualRoutes)
|
|
||||||
|
for i := range len(tc.expectedRoutes) {
|
||||||
|
assert.Equal(t, gjson.GetBytes(expectedRoutes, fmt.Sprintf("$[%d].receiver", i)).String(), gjson.GetBytes(actualRoutes, fmt.Sprintf("$[%d].receiver", i)).String())
|
||||||
|
assert.ElementsMatch(t, gjson.GetBytes(expectedRoutes, fmt.Sprintf("$[%d].matchers", i)).Array(), gjson.GetBytes(actualRoutes, fmt.Sprintf("$[%d].matchers", i)).Array())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user