mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Various fixes for the alerts endpoint (#33182)
A set of fixes for the GET alert and groups endpoints. - First, is the fact that the default values where not being for the query params. I've introduced a new method in the Grafana context that allow us to do this. - Second, is the fact that alerts were never being transitioned to active. To my surprise this is actually done by the inhibitor in the pipeline - if an alert is not muted, or inhibited then it's active. - Third, I have added an integration test to cover for regressions. Signed-off-by: Josue Abreu <josue@grafana.com>
This commit is contained in:
41
pkg/models/context_test.go
Normal file
41
pkg/models/context_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
func TestQueryBoolWithDefault(t *testing.T) {
|
||||
tc := map[string]struct {
|
||||
url string
|
||||
defaultValue bool
|
||||
expected bool
|
||||
}{
|
||||
"with no value specified, the default value is returned": {
|
||||
url: "http://localhost/api/v2/alerts",
|
||||
defaultValue: true,
|
||||
expected: true,
|
||||
},
|
||||
"with a value specified, the default value is overridden": {
|
||||
url: "http://localhost/api/v2/alerts?silenced=false",
|
||||
defaultValue: true,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range tc {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", tt.url, nil)
|
||||
require.NoError(t, err)
|
||||
r := ReqContext{
|
||||
Context: &macaron.Context{
|
||||
Req: macaron.Request{Request: req},
|
||||
},
|
||||
}
|
||||
require.Equal(t, tt.expected, r.QueryBoolWithDefault("silenced", tt.defaultValue))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user