Repository: prometheus/prometheus
File: web/api/v1/api_test.go (Go)

Code before:
	RemoteReadConfigs:  []*config.RemoteReadConfig{},
	OTLPConfig:         config.OTLPConfig{},
}

var sampleFlagMap = map[string]string{
	"flag1": "value1",
	"flag2": "value2",
}

func appendExemplars(t testing.TB, s storage.Storage, ex []exemplar.QueryResult) {
	t.Helper()

	now := time.Now()
	app := s.AppenderV2(t.Context())
	for _, ed := range ex {
		_, err := app.Append(0, ed.SeriesLabels, 0, timestamp.FromTime(now), 0, nil, nil, storage.AOptions{Exemplars: ed.Exemplars})
		require.NoError(t, err)
	}
	require.NoError(t, app.Commit())
}

func TestEndpoints(t *testing.T) {
	s := promqltest.LoadedStorage(t, `
		load 1m
			test_metric1{foo="bar"} 0+100x100
			test_metric1{foo="boo"} 1+0x100
			test_metric2{foo="boo"} 1+0x100
			test_metric3{foo="bar", dup="1"} 1+0x100
			test_metric3{foo="boo", dup="1"} 1+0x100
			test_metric4{foo="bar", dup="1"} 1+0x100
			test_metric4{foo="boo", dup="1"} 1+0x100
			test_metric4{foo="boo"} 1+0x100
			test_metric5{"host.name"="localhost"} 1+0x100
			test_metric5{"junk\n{},=:  chars"="bar"} 1+0x100
	`)

	// Add exemplar testdata here, given promqltest does not support exemplars.
	start := time.Unix(0, 0)
	exemplars := []exemplar.QueryResult{
		{
			SeriesLabels: labels.FromStrings("__name__", "test_metric3", "foo", "boo", "dup", "1"),
			Exemplars: []exemplar.Exemplar{
				{
					Labels: labels.FromStrings("id", "abc"),
					Value:  10,
					Ts:     timestamp.FromTime(start.Add(2 * time.Second)),
				},
			},
		},
		{
			SeriesLabels: labels.FromStrings("__name__", "test_metric4", "foo", "bar", "dup", "1"),

Review comment (suggestion):
nit: please don't mix style changes with logic changes

```suggestion
	storage := promqltest.LoadedStorage(t, `
```

Code after:
	RemoteReadConfigs:  []*config.RemoteReadConfig{},
	OTLPConfig:         config.OTLPConfig{},
}

var sampleFlagMap = map[string]string{
	"flag1": "value1",
	"flag2": "value2",
}

func appendExemplars(t testing.TB, s storage.Storage, ex []exemplar.QueryResult) {
	t.Helper()

	// TODO(bwplotka): Use AppenderV2.AppendExemplar per series flow
	// once its implemented: https://github.com/prometheus/prometheus/issues/17632#issuecomment-3759315095
	app := s.Appender(t.Context())
	for _, ed := range ex {
		for _, e := range ed.Exemplars {
			_, err := app.AppendExemplar(0, ed.SeriesLabels, e)
			require.NoError(t, err)
		}
	}
	require.NoError(t, app.Commit())
}

func TestEndpoints(t *testing.T) {
	s := promqltest.LoadedStorage(t, `
		load 1m
			test_metric1{foo="bar"} 0+100x100
			test_metric1{foo="boo"} 1+0x100
			test_metric2{foo="boo"} 1+0x100
			test_metric3{foo="bar", dup="1"} 1+0x100
			test_metric3{foo="boo", dup="1"} 1+0x100
			test_metric4{foo="bar", dup="1"} 1+0x100
			test_metric4{foo="boo", dup="1"} 1+0x100
			test_metric4{foo="boo"} 1+0x100
			test_metric5{"host.name"="localhost"} 1+0x100
			test_metric5{"junk\n{},=:  chars"="bar"} 1+0x100
	`)

	// Add exemplar testdata here, given promqltest does not support exemplars.
	start := time.Unix(0, 0)
	exemplars := []exemplar.QueryResult{
		{
			SeriesLabels: labels.FromStrings("__name__", "test_metric3", "foo", "boo", "dup", "1"),
			Exemplars: []exemplar.Exemplar{
				{
					Labels: labels.FromStrings("id", "abc"),
					Value:  10,
					Ts:     timestamp.FromTime(start.Add(2 * time.Second)),
				},
			},