Repository: prometheus/prometheus
File: storage/remote/otlptranslator/prometheusremotewrite/helper_test.go (Go)

Code before:
			name: "summary without start time and without scope promotion",
			metric: func() pmetric.Metric {
				metric := pmetric.NewMetric()
				metric.SetName("test_summary")
				metric.SetEmptySummary()

				dp := metric.Summary().DataPoints().AppendEmpty()
				dp.SetTimestamp(ts)

				return metric
			},
			scope:        defaultScope,
			promoteScope: false,
			want: func() []combinedSample {
				return []combinedSample{
					{
						metricFamilyName: "test_summary",
						ls: labels.FromStrings(
							model.MetricNameLabel, "test_summary"+sumStr,
						),
						t: convertTimeStamp(ts),
						v: 0,
					},
					{
						metricFamilyName: "test_summary",
						ls: labels.FromStrings(
							model.MetricNameLabel, "test_summary"+countStr,
						),
						t: convertTimeStamp(ts),
						v: 0,
					},
				}
			},
		},
		{
			name: "summary without start time and without scope promotion and some quantiles",
			metric: func() pmetric.Metric {
				metric := pmetric.NewMetric()
				metric.SetName("test_summary")
				metric.SetEmptySummary()

				dp := metric.Summary().DataPoints().AppendEmpty()
				dp.SetTimestamp(ts)
				dp.SetCount(50)
				dp.SetSum(100)
				dp.QuantileValues().EnsureCapacity(2)
				h := dp.QuantileValues().AppendEmpty()
				h.SetQuantile(0.5)
				h.SetValue(30)
				n := dp.QuantileValues().AppendEmpty()
				n.SetQuantile(0.9)

Review comment (bug):
Could you switch the argument order here? When reading the godoc of RequireEqual I see
```
func testutil.RequireEqual(t testing.TB, expected any, actual any, msgAndArgs ...any)
```

The test output is super confusing when it fails with the incorrect argument order

Code after:
				PromoteResourceAttributes: NewPromoteResourceAttributes(config.OTLPConfig{
					PromoteAllResourceAttributes: tc.promoteAllResourceAttributes,
					PromoteResourceAttributes:    tc.promoteResourceAttributes,
					IgnoreResourceAttributes:     tc.ignoreResourceAttributes,
				}),
				PromoteScopeMetadata:                 tc.promoteScope,
				LabelNameUnderscoreSanitization:      tc.labelNameUnderscoreLabelSanitization,
				LabelNamePreserveMultipleUnderscores: tc.labelNamePreserveMultipleUnderscores,
			}
			// Use test case specific resource/attrs if provided, otherwise use defaults
			// Check if tc.resource is initialized (non-zero) by trying to get its attributes
			testResource := resource
			testAttrs := attrs
			// For pcommon types, we can check if they're non-zero by seeing if they have attributes
			// Since zero-initialized Resource is not valid, we use a simple heuristic:
			// if the struct has been explicitly set in the test case, use it
			if tc.resource != (pcommon.Resource{}) {
				testResource = tc.resource
			}
			if tc.attrs != (pcommon.Map{}) {
				testAttrs = tc.attrs
			}
			lbls, err := c.createAttributes(testResource, testAttrs, tc.scope, settings, tc.ignoreAttrs, false, Metadata{}, model.MetricNameLabel, "test_metric")
			require.NoError(t, err)

			testutil.RequireEqual(t, lbls, tc.expectedLabels)
		})
	}
}

func Test_convertTimeStamp(t *testing.T) {
	tests := []struct {
		name string
		arg  pcommon.Timestamp
		want int64
	}{
		{"zero", 0, 0},
		{"1ms", 1_000_000, 1},
		{"1s", pcommon.Timestamp(time.Unix(1, 0).UnixNano()), 1000},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := convertTimeStamp(tt.arg)
			require.Equal(t, tt.want, got)
		})
	}
}

func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
	scopeAttrs := pcommon.NewMap()
	scopeAttrs.FromRaw(map[string]any{