|
|
|
|
@ -2,9 +2,12 @@ package v0alpha1_test |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend" |
|
|
|
|
data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1" |
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
|
|
|
|
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1" |
|
|
|
|
@ -76,3 +79,39 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
}`, string(out)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetResponseCode(t *testing.T) { |
|
|
|
|
t.Run("return 200 if no errors in responses", func(t *testing.T) { |
|
|
|
|
assert.Equal(t, 200, query.GetResponseCode(&backend.QueryDataResponse{ |
|
|
|
|
Responses: map[string]backend.DataResponse{ |
|
|
|
|
"A": { |
|
|
|
|
Error: nil, |
|
|
|
|
}, |
|
|
|
|
"B": { |
|
|
|
|
Error: nil, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
})) |
|
|
|
|
}) |
|
|
|
|
t.Run("return 400 if there is an error in the responses", func(t *testing.T) { |
|
|
|
|
assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{ |
|
|
|
|
Responses: map[string]backend.DataResponse{ |
|
|
|
|
"A": { |
|
|
|
|
Error: fmt.Errorf("some wild error"), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
})) |
|
|
|
|
}) |
|
|
|
|
t.Run("return 400 if there is a partial error", func(t *testing.T) { |
|
|
|
|
assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{ |
|
|
|
|
Responses: map[string]backend.DataResponse{ |
|
|
|
|
"A": { |
|
|
|
|
Error: nil, |
|
|
|
|
}, |
|
|
|
|
"B": { |
|
|
|
|
Error: fmt.Errorf("some partial error"), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
})) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|