blob: 11cea216f33906100ed1d4a6a5293a347127e7e0 [file] [edit]
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package pushgateway
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"go.skia.org/infra/go/httputils"
)
func TestPush(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/metrics/job/test_job" {
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.Equal(t, "test_metric_name test_metric_value\n", string(body))
} else {
require.Fail(t, fmt.Sprintf("Unexpected path: %s", r.URL.Path))
}
}))
defer ts.Close()
p := New(httputils.NewTimeoutClient(), "test_job", ts.URL)
err := p.Push(context.Background(), "test_metric_name", "test_metric_value")
require.NoError(t, err)
}