Repository: prometheus/prometheus
File: storage/remote/write_test.go (Go)

Code before:
		t.Run(testCase.name, func(t *testing.T) {
			appendable := handleOTLP(t, exportRequest, testCase.otlpCfg, testCase.typeAndUnitLabels)
			for _, sample := range testCase.expectedSamples {
				requireContainsSample(t, appendable.samples, sample)
			}
			require.Len(t, appendable.samples, 12)   // 1 (counter) + 1 (gauge) + 1 (target_info) + 7 (hist_bucket) + 2 (hist_sum, hist_count)
			require.Len(t, appendable.histograms, 1) // 1 (exponential histogram)
			require.Len(t, appendable.exemplars, 1)  // 1 (exemplar)
		})
	}
}

func requireContainsSample(t *testing.T, actual []mockSample, expected mockSample) {
	t.Helper()

	for _, got := range actual {
		if labels.Equal(expected.l, got.l) && expected.t == got.t && expected.v == got.v {
			return
		}
	}
	require.Fail(t, fmt.Sprintf("Sample not found: \n"+
		"expected: %v\n"+
		"actual  : %v", expected, actual))
}

func handleOTLP(t *testing.T, exportRequest pmetricotlp.ExportRequest, otlpCfg config.OTLPConfig, typeAndUnitLabels bool) *mockAppendable {
	buf, err := exportRequest.MarshalProto()
	require.NoError(t, err)

	req, err := http.NewRequest("", "", bytes.NewReader(buf))
	require.NoError(t, err)
	req.Header.Set("Content-Type", "application/x-protobuf")

	appendable := &mockAppendable{}
	handler := NewOTLPWriteHandler(nil, nil, appendable, func() config.Config {
		return config.Config{
			OTLPConfig: otlpCfg,
		}
	}, OTLPOptions{AddTypeAndUnitLabels: typeAndUnitLabels})
	recorder := httptest.NewRecorder()
	handler.ServeHTTP(recorder, req)

	resp := recorder.Result()
	require.Equal(t, http.StatusOK, resp.StatusCode)

	return appendable
}

func generateOTLPWriteRequest(timestamp time.Time) pmetricotlp.ExportRequest {
	d := pmetric.NewMetrics()


Review comment (suggestion):
[Nit] For consistency:
```suggestion
func handleOTLP(t *testing.T, exportRequest pmetricotlp.ExportRequest, otlpCfg config.OTLPConfig, enableTypeAndUnitLabels bool) *mockAppendable {
```

Code after:
		t.Run(testCase.name, func(t *testing.T) {
			appendable := handleOTLP(t, exportRequest, testCase.otlpCfg, testCase.typeAndUnitLabels)
			for _, sample := range testCase.expectedSamples {
				requireContainsSample(t, appendable.samples, sample)
			}
			require.Len(t, appendable.samples, 12)   // 1 (counter) + 1 (gauge) + 1 (target_info) + 7 (hist_bucket) + 2 (hist_sum, hist_count)
			require.Len(t, appendable.histograms, 1) // 1 (exponential histogram)
			require.Len(t, appendable.exemplars, 1)  // 1 (exemplar)
		})
	}
}

func requireContainsSample(t *testing.T, actual []mockSample, expected mockSample) {
	t.Helper()

	for _, got := range actual {
		if labels.Equal(expected.l, got.l) && expected.t == got.t && expected.v == got.v {
			return
		}
	}
	require.Fail(t, fmt.Sprintf("Sample not found: \n"+
		"expected: %v\n"+
		"actual  : %v", expected, actual))
}

func handleOTLP(t *testing.T, exportRequest pmetricotlp.ExportRequest, otlpCfg config.OTLPConfig, typeAndUnitLabels bool) *mockAppendable {
	buf, err := exportRequest.MarshalProto()
	require.NoError(t, err)

	req, err := http.NewRequest("", "", bytes.NewReader(buf))
	require.NoError(t, err)
	req.Header.Set("Content-Type", "application/x-protobuf")

	appendable := &mockAppendable{}
	handler := NewOTLPWriteHandler(nil, nil, appendable, func() config.Config {
		return config.Config{
			OTLPConfig: otlpCfg,
		}
	}, OTLPOptions{EnableTypeAndUnitLabels: typeAndUnitLabels})
	recorder := httptest.NewRecorder()
	handler.ServeHTTP(recorder, req)

	resp := recorder.Result()
	require.Equal(t, http.StatusOK, resp.StatusCode)

	return appendable
}

func generateOTLPWriteRequest(timestamp time.Time) pmetricotlp.ExportRequest {
	d := pmetric.NewMetrics()