...

Source file src/github.com/cybertec-postgresql/pgwatch/v6/internal/testutil/http_test.go

Documentation: github.com/cybertec-postgresql/pgwatch/v6/internal/testutil

     1  package testutil_test
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/cybertec-postgresql/pgwatch/v6/internal/testutil"
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  // TestNewFakeExporter asserts the fake Prometheus exporter serves the
    14  // supplied body verbatim with the standard exposition Content-Type.
    15  func TestNewFakeExporter(t *testing.T) {
    16  	const body = "# HELP m help\n# TYPE m gauge\nm 42\n"
    17  	srv := testutil.NewFakeExporter(t, body)
    18  
    19  	resp, err := http.Get(srv.URL)
    20  	require.NoError(t, err)
    21  	defer func() { _ = resp.Body.Close() }()
    22  
    23  	assert.Equal(t, http.StatusOK, resp.StatusCode)
    24  	assert.Equal(t, "text/plain; version=0.0.4", resp.Header.Get("Content-Type"))
    25  
    26  	b, err := io.ReadAll(resp.Body)
    27  	require.NoError(t, err)
    28  	assert.Equal(t, body, string(b))
    29  }
    30