mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
tests: API: Use jsoniter when encoding
So that tests use the same encoding as the api. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
2c4a36376d
commit
5a339ba359
|
@ -15,7 +15,6 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -35,6 +34,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
config_util "github.com/prometheus/common/config"
|
config_util "github.com/prometheus/common/config"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -910,6 +910,7 @@ func TestStats(t *testing.T) {
|
||||||
require.IsType(t, &QueryData{}, i)
|
require.IsType(t, &QueryData{}, i)
|
||||||
qd := i.(*QueryData)
|
qd := i.(*QueryData)
|
||||||
require.NotNil(t, qd.Stats)
|
require.NotNil(t, qd.Stats)
|
||||||
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
j, err := json.Marshal(qd.Stats)
|
j, err := json.Marshal(qd.Stats)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.JSONEq(t, `{"custom":"Custom Value"}`, string(j))
|
require.JSONEq(t, `{"custom":"Custom Value"}`, string(j))
|
||||||
|
@ -2895,6 +2896,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.responseAsJSON != "" {
|
if test.responseAsJSON != "" {
|
||||||
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
s, err := json.Marshal(res.data)
|
s, err := json.Marshal(res.data)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.JSONEq(t, test.responseAsJSON, string(s))
|
require.JSONEq(t, test.responseAsJSON, string(s))
|
||||||
|
|
Loading…
Reference in a new issue