The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/expr/nodes_test.go

42 lines
823 B

package expr
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
type expectedError struct{}
func (e expectedError) Error() string {
return "expected"
}
func TestQueryError_Error(t *testing.T) {
e := QueryError{
RefID: "A",
Err: errors.New("this is an error message"),
}
assert.EqualError(t, e, "failed to execute query A: this is an error message")
}
func TestQueryError_Unwrap(t *testing.T) {
t.Run("errors.Is", func(t *testing.T) {
expectedIsErr := errors.New("expected")
e := QueryError{
RefID: "A",
Err: expectedIsErr,
}
assert.True(t, errors.Is(e, expectedIsErr))
})
t.Run("errors.As", func(t *testing.T) {
e := QueryError{
RefID: "A",
Err: expectedError{},
}
var expectedAsError expectedError
assert.True(t, errors.As(e, &expectedAsError))
})
}