// Code generated by mdatagen. DO NOT EDIT.

package metadata

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"go.uber.org/zap"
	"go.uber.org/zap/zaptest/observer"

	"go.opentelemetry.io/collector/pdata/pcommon"
	"go.opentelemetry.io/collector/pdata/pmetric"
	"go.opentelemetry.io/collector/receiver/receivertest"
)

type testDataSet int

const (
	testDataSetDefault testDataSet = iota
	testDataSetAll
	testDataSetNone
	testDataSetReag
)

func TestMetricsBuilder(t *testing.T) {
	tests := []struct {
		name        string
		metricsSet  testDataSet
		resAttrsSet testDataSet
		expectEmpty bool
	}{
		{
			name: "default",
		},
		{
			name:        "all_set",
			metricsSet:  testDataSetAll,
			resAttrsSet: testDataSetAll,
		},
		{
			name:        "reaggregate_set",
			metricsSet:  testDataSetReag,
			resAttrsSet: testDataSetReag,
		},
		{
			name:        "none_set",
			metricsSet:  testDataSetNone,
			resAttrsSet: testDataSetNone,
			expectEmpty: true,
		},
		{
			name:        "filter_set_include",
			resAttrsSet: testDataSetAll,
		},
		{
			name:        "filter_set_exclude",
			resAttrsSet: testDataSetAll,
			expectEmpty: true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			start := pcommon.Timestamp(1_000_000_000)
			ts := pcommon.Timestamp(1_000_001_000)
			observedZapCore, observedLogs := observer.New(zap.WarnLevel)
			settings := receivertest.NewNopSettings(receivertest.NopType)
			settings.Logger = zap.New(observedZapCore)
			mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, tt.name), settings, WithStartTime(start))
			aggMap := make(map[string]string) // contains the aggregation strategies for each metric name
			aggMap["default.metric"] = mb.metricDefaultMetric.config.AggregationStrategy
			aggMap["metric.input_type"] = mb.metricMetricInputType.config.AggregationStrategy
			aggMap["optional.metric"] = mb.metricOptionalMetric.config.AggregationStrategy
			aggMap["optional.metric.empty_unit"] = mb.metricOptionalMetricEmptyUnit.config.AggregationStrategy
			aggMap["reaggregate.metric"] = mb.metricReaggregateMetric.config.AggregationStrategy
			aggMap["reaggregate.metric.with_required"] = mb.metricReaggregateMetricWithRequired.config.AggregationStrategy
			aggMap["system.cpu.time"] = mb.metricSystemCPUTime.config.AggregationStrategy
			aggMap["system.memory.usage"] = mb.metricSystemMemoryUsage.config.AggregationStrategy

			expectedWarnings := 0
			if tt.metricsSet == testDataSetDefault {
				assert.Equal(t, "[WARNING] Please set `enabled` field explicitly for `default.metric`: This metric will be disabled by default soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.metricsSet == testDataSetDefault || tt.metricsSet == testDataSetAll {
				assert.Equal(t, "[WARNING] `default.metric.to_be_removed` should not be enabled: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.metricsSet == testDataSetAll || tt.metricsSet == testDataSetNone {
				assert.Equal(t, "[WARNING] `optional.metric` should not be configured: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.metricsSet == testDataSetAll || tt.metricsSet == testDataSetNone {
				assert.Equal(t, "[WARNING] `optional.metric.empty_unit` should not be configured: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.resAttrsSet == testDataSetDefault {
				assert.Equal(t, "[WARNING] Please set `enabled` field explicitly for `string.resource.attr_disable_warning`: This resource_attribute will be disabled by default soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.resAttrsSet == testDataSetAll || tt.resAttrsSet == testDataSetNone {
				assert.Equal(t, "[WARNING] `string.resource.attr_remove_warning` should not be configured: This resource_attribute is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.resAttrsSet == testDataSetDefault || tt.resAttrsSet == testDataSetAll {
				assert.Equal(t, "[WARNING] `string.resource.attr_to_be_removed` should not be enabled: This resource_attribute is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.resAttrsSet == testDataSetAll {
				assert.Equal(t, "[WARNING] `string.resource.disabled_attr_to_be_removed` should not be enabled: This resource_attribute is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message)
				expectedWarnings++
			}
			if tt.metricsSet != testDataSetReag {
				assert.Equal(t, expectedWarnings, observedLogs.Len())
			}

			defaultMetricsCount := 0
			allMetricsCount := 0
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordDefaultMetricDataPoint(ts, 1, "string_attr-val", 19, AttributeEnumAttrRed, []any{"slice_attr-item1", "slice_attr-item2"}, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"}, true, WithConditionalIntAttrMetricAttribute(20), WithConditionalStringAttrMetricAttribute("conditional_string_attr-val"))
			if tt.name == "reaggregate_set" {
				mb.RecordDefaultMetricDataPoint(ts, 3, "string_attr-val-2", 20, AttributeEnumAttrGreen, []any{"slice_attr-item3", "slice_attr-item4"}, map[string]any{"key3": "map_attr-val3", "key4": "map_attr-val4"}, false, WithConditionalIntAttrMetricAttribute(20), WithConditionalStringAttrMetricAttribute("conditional_string_attr-val"))
			}
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordDefaultMetricToBeRemovedDataPoint(ts, 1)
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordMetricInputTypeDataPoint(ts, "1", "string_attr-val", 19, AttributeEnumAttrRed, []any{"slice_attr-item1", "slice_attr-item2"}, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"})
			if tt.name == "reaggregate_set" {
				mb.RecordMetricInputTypeDataPoint(ts, "3", "string_attr-val-2", 20, AttributeEnumAttrGreen, []any{"slice_attr-item3", "slice_attr-item4"}, map[string]any{"key3": "map_attr-val3", "key4": "map_attr-val4"})
			}

			allMetricsCount++
			mb.RecordOptionalMetricDataPoint(ts, 1, "string_attr-val", true, false, WithConditionalStringAttrMetricAttribute("conditional_string_attr-val"))
			if tt.name == "reaggregate_set" {
				mb.RecordOptionalMetricDataPoint(ts, 3, "string_attr-val-2", false, true, WithConditionalStringAttrMetricAttribute("conditional_string_attr-val"))
			}

			allMetricsCount++
			mb.RecordOptionalMetricEmptyUnitDataPoint(ts, 1, "string_attr-val", true)
			if tt.name == "reaggregate_set" {
				mb.RecordOptionalMetricEmptyUnitDataPoint(ts, 3, "string_attr-val-2", false)
			}
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordReaggregateMetricDataPoint(ts, 1, "string_attr-val", true)
			if tt.name == "reaggregate_set" {
				mb.RecordReaggregateMetricDataPoint(ts, 3, "string_attr-val-2", false)
			}
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordReaggregateMetricWithRequiredDataPoint(ts, 1, "required_string_attr-val", "string_attr-val", true)
			if tt.name == "reaggregate_set" {
				mb.RecordReaggregateMetricWithRequiredDataPoint(ts, 3, "required_string_attr-val", "string_attr-val-2", false)
			}
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordSystemCPUTimeDataPoint(ts, 1, "cpu-val")
			if tt.name == "reaggregate_set" {
				mb.RecordSystemCPUTimeDataPoint(ts, 3, "cpu-val-2")
			}
			defaultMetricsCount++
			allMetricsCount++
			mb.RecordSystemMemoryUsageDataPoint(ts, 1, AttributeStateBuffered)
			if tt.name == "reaggregate_set" {
				mb.RecordSystemMemoryUsageDataPoint(ts, 3, AttributeStateCached)
			}

			rb := mb.NewResourceBuilder()
			rb.SetHostArch("host.arch-val")
			rb.SetMapResourceAttr(map[string]any{"key1": "map.resource.attr-val1", "key2": "map.resource.attr-val2"})
			rb.SetOptionalResourceAttr("optional.resource.attr-val")
			rb.SetSliceResourceAttr([]any{"slice.resource.attr-item1", "slice.resource.attr-item2"})
			rb.SetStringEnumResourceAttrOne()
			rb.SetStringResourceAttr("string.resource.attr-val")
			rb.SetStringResourceAttrDisableWarning("string.resource.attr_disable_warning-val")
			rb.SetStringResourceAttrRemoveWarning("string.resource.attr_remove_warning-val")
			rb.SetStringResourceAttrToBeRemoved("string.resource.attr_to_be_removed-val")
			rb.SetStringResourceDisabledAttrToBeRemoved("string.resource.disabled_attr_to_be_removed-val")
			res := rb.Emit()
			metrics := mb.Emit(WithResource(res))
			if tt.name == "reaggregate_set" {
				assert.Empty(t, mb.metricDefaultMetric.aggDataPoints)
				assert.Empty(t, mb.metricMetricInputType.aggDataPoints)
				assert.Empty(t, mb.metricOptionalMetric.aggDataPoints)
				assert.Empty(t, mb.metricOptionalMetricEmptyUnit.aggDataPoints)
				assert.Empty(t, mb.metricReaggregateMetric.aggDataPoints)
				assert.Empty(t, mb.metricReaggregateMetricWithRequired.aggDataPoints)
				assert.Empty(t, mb.metricSystemCPUTime.aggDataPoints)
				assert.Empty(t, mb.metricSystemMemoryUsage.aggDataPoints)
			}

			if tt.expectEmpty {
				assert.Equal(t, 0, metrics.ResourceMetrics().Len())
				return
			}

			var allMetricsList []pmetric.Metric
			totalMetricsCount := 0
			for ri := 0; ri < metrics.ResourceMetrics().Len(); ri++ {
				rm := metrics.ResourceMetrics().At(ri)
				assert.Equal(t, 1, rm.ScopeMetrics().Len())
				ms := rm.ScopeMetrics().At(0).Metrics()
				totalMetricsCount += ms.Len()
				for mi := 0; mi < ms.Len(); mi++ {
					allMetricsList = append(allMetricsList, ms.At(mi))
				}
			}
			if tt.metricsSet == testDataSetDefault {
				assert.Equal(t, defaultMetricsCount, totalMetricsCount)
			}
			if tt.metricsSet == testDataSetAll {
				assert.Equal(t, allMetricsCount, totalMetricsCount)
			}
			validatedMetrics := make(map[string]bool)
			for _, mi := range allMetricsList {
				switch mi.Name() {
				case "default.metric":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["default.metric"], "Found a duplicate in the metrics slice: default.metric")
						validatedMetrics["default.metric"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						assert.Equal(t, int64(1), dp.IntValue())
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						overriddenIntAttrAttrVal, ok := dp.Attributes().Get("state")
						assert.True(t, ok)
						assert.EqualValues(t, 19, overriddenIntAttrAttrVal.Int())
						enumAttrAttrVal, ok := dp.Attributes().Get("enum_attr")
						assert.True(t, ok)
						assert.Equal(t, "red", enumAttrAttrVal.Str())
						sliceAttrAttrVal, ok := dp.Attributes().Get("slice_attr")
						assert.True(t, ok)
						assert.Equal(t, []any{"slice_attr-item1", "slice_attr-item2"}, sliceAttrAttrVal.Slice().AsRaw())
						mapAttrAttrVal, ok := dp.Attributes().Get("map_attr")
						assert.True(t, ok)
						assert.Equal(t, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"}, mapAttrAttrVal.Map().AsRaw())
						conditionalIntAttrAttrVal, ok := dp.Attributes().Get("conditional_int_attr")
						assert.True(t, ok)
						assert.EqualValues(t, 20, conditionalIntAttrAttrVal.Int())
						conditionalStringAttrAttrVal, ok := dp.Attributes().Get("conditional_string_attr")
						assert.True(t, ok)
						assert.Equal(t, "conditional_string_attr-val", conditionalStringAttrAttrVal.Str())
					} else {
						assert.False(t, validatedMetrics["default.metric"], "Found a duplicate in the metrics slice: default.metric")
						validatedMetrics["default.metric"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						switch aggMap["default.metric"] {
						case "sum":
							assert.Equal(t, int64(4), dp.IntValue())
						case "avg":
							assert.Equal(t, int64(2), dp.IntValue())
						case "min":
							assert.Equal(t, int64(1), dp.IntValue())
						case "max":
							assert.Equal(t, int64(3), dp.IntValue())
						}
						_, ok := dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("state")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("enum_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("slice_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("map_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("opt_in_bool_attr")
						assert.False(t, ok)
					}
				case "default.metric.to_be_removed":
					assert.False(t, validatedMetrics["default.metric.to_be_removed"], "Found a duplicate in the metrics slice: default.metric.to_be_removed")
					validatedMetrics["default.metric.to_be_removed"] = true
					assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
					assert.Equal(t, 1, mi.Sum().DataPoints().Len())
					assert.Equal(t, "[DEPRECATED] Non-monotonic delta sum double metric enabled by default.", mi.Description())
					assert.Equal(t, "s", mi.Unit())
					assert.False(t, mi.Sum().IsMonotonic())
					assert.Equal(t, pmetric.AggregationTemporalityDelta, mi.Sum().AggregationTemporality())
					dp := mi.Sum().DataPoints().At(0)
					assert.Equal(t, start, dp.StartTimestamp())
					assert.Equal(t, ts, dp.Timestamp())
					assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
					assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
				case "metric.input_type":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["metric.input_type"], "Found a duplicate in the metrics slice: metric.input_type")
						validatedMetrics["metric.input_type"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric with string input_type enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						assert.Equal(t, int64(1), dp.IntValue())
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						overriddenIntAttrAttrVal, ok := dp.Attributes().Get("state")
						assert.True(t, ok)
						assert.EqualValues(t, 19, overriddenIntAttrAttrVal.Int())
						enumAttrAttrVal, ok := dp.Attributes().Get("enum_attr")
						assert.True(t, ok)
						assert.Equal(t, "red", enumAttrAttrVal.Str())
						sliceAttrAttrVal, ok := dp.Attributes().Get("slice_attr")
						assert.True(t, ok)
						assert.Equal(t, []any{"slice_attr-item1", "slice_attr-item2"}, sliceAttrAttrVal.Slice().AsRaw())
						mapAttrAttrVal, ok := dp.Attributes().Get("map_attr")
						assert.True(t, ok)
						assert.Equal(t, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"}, mapAttrAttrVal.Map().AsRaw())
					} else {
						assert.False(t, validatedMetrics["metric.input_type"], "Found a duplicate in the metrics slice: metric.input_type")
						validatedMetrics["metric.input_type"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric with string input_type enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						switch aggMap["metric.input_type"] {
						case "sum":
							assert.Equal(t, int64(4), dp.IntValue())
						case "avg":
							assert.Equal(t, int64(2), dp.IntValue())
						case "min":
							assert.Equal(t, int64(1), dp.IntValue())
						case "max":
							assert.Equal(t, int64(3), dp.IntValue())
						}
						_, ok := dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("state")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("enum_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("slice_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("map_attr")
						assert.False(t, ok)
					}
				case "optional.metric":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["optional.metric"], "Found a duplicate in the metrics slice: optional.metric")
						validatedMetrics["optional.metric"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						booleanAttrAttrVal, ok := dp.Attributes().Get("boolean_attr")
						assert.True(t, ok)
						assert.True(t, booleanAttrAttrVal.Bool())
						booleanAttr2AttrVal, ok := dp.Attributes().Get("boolean_attr2")
						assert.True(t, ok)
						assert.False(t, booleanAttr2AttrVal.Bool())
						conditionalStringAttrAttrVal, ok := dp.Attributes().Get("conditional_string_attr")
						assert.True(t, ok)
						assert.Equal(t, "conditional_string_attr-val", conditionalStringAttrAttrVal.Str())
					} else {
						assert.False(t, validatedMetrics["optional.metric"], "Found a duplicate in the metrics slice: optional.metric")
						validatedMetrics["optional.metric"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						switch aggMap["optional.metric"] {
						case "sum":
							assert.InDelta(t, float64(4), dp.DoubleValue(), 0.01)
						case "avg":
							assert.InDelta(t, float64(2), dp.DoubleValue(), 0.01)
						case "min":
							assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						case "max":
							assert.InDelta(t, float64(3), dp.DoubleValue(), 0.01)
						}
						_, ok := dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("boolean_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("boolean_attr2")
						assert.False(t, ok)
					}
				case "optional.metric.empty_unit":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["optional.metric.empty_unit"], "Found a duplicate in the metrics slice: optional.metric.empty_unit")
						validatedMetrics["optional.metric.empty_unit"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", mi.Description())
						assert.Empty(t, mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						booleanAttrAttrVal, ok := dp.Attributes().Get("boolean_attr")
						assert.True(t, ok)
						assert.True(t, booleanAttrAttrVal.Bool())
					} else {
						assert.False(t, validatedMetrics["optional.metric.empty_unit"], "Found a duplicate in the metrics slice: optional.metric.empty_unit")
						validatedMetrics["optional.metric.empty_unit"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", mi.Description())
						assert.Empty(t, mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						switch aggMap["optional.metric.empty_unit"] {
						case "sum":
							assert.InDelta(t, float64(4), dp.DoubleValue(), 0.01)
						case "avg":
							assert.InDelta(t, float64(2), dp.DoubleValue(), 0.01)
						case "min":
							assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						case "max":
							assert.InDelta(t, float64(3), dp.DoubleValue(), 0.01)
						}
						_, ok := dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("boolean_attr")
						assert.False(t, ok)
					}
				case "reaggregate.metric":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["reaggregate.metric"], "Found a duplicate in the metrics slice: reaggregate.metric")
						validatedMetrics["reaggregate.metric"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "Metric for testing spatial reaggregation", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						booleanAttrAttrVal, ok := dp.Attributes().Get("boolean_attr")
						assert.True(t, ok)
						assert.True(t, booleanAttrAttrVal.Bool())
					} else {
						assert.False(t, validatedMetrics["reaggregate.metric"], "Found a duplicate in the metrics slice: reaggregate.metric")
						validatedMetrics["reaggregate.metric"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "Metric for testing spatial reaggregation", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						switch aggMap["reaggregate.metric"] {
						case "sum":
							assert.InDelta(t, float64(4), dp.DoubleValue(), 0.01)
						case "avg":
							assert.InDelta(t, float64(2), dp.DoubleValue(), 0.01)
						case "min":
							assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						case "max":
							assert.InDelta(t, float64(3), dp.DoubleValue(), 0.01)
						}
						_, ok := dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("boolean_attr")
						assert.False(t, ok)
					}
				case "reaggregate.metric.with_required":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["reaggregate.metric.with_required"], "Found a duplicate in the metrics slice: reaggregate.metric.with_required")
						validatedMetrics["reaggregate.metric.with_required"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "Metric for testing spatial reaggregation with required attributes", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						requiredStringAttrAttrVal, ok := dp.Attributes().Get("required_string_attr")
						assert.True(t, ok)
						assert.Equal(t, "required_string_attr-val", requiredStringAttrAttrVal.Str())
						stringAttrAttrVal, ok := dp.Attributes().Get("string_attr")
						assert.True(t, ok)
						assert.Equal(t, "string_attr-val", stringAttrAttrVal.Str())
						booleanAttrAttrVal, ok := dp.Attributes().Get("boolean_attr")
						assert.True(t, ok)
						assert.True(t, booleanAttrAttrVal.Bool())
					} else {
						assert.False(t, validatedMetrics["reaggregate.metric.with_required"], "Found a duplicate in the metrics slice: reaggregate.metric.with_required")
						validatedMetrics["reaggregate.metric.with_required"] = true
						assert.Equal(t, pmetric.MetricTypeGauge, mi.Type())
						assert.Equal(t, 1, mi.Gauge().DataPoints().Len())
						assert.Equal(t, "Metric for testing spatial reaggregation with required attributes", mi.Description())
						assert.Equal(t, "1", mi.Unit())
						dp := mi.Gauge().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType())
						switch aggMap["reaggregate.metric.with_required"] {
						case "sum":
							assert.InDelta(t, float64(4), dp.DoubleValue(), 0.01)
						case "avg":
							assert.InDelta(t, float64(2), dp.DoubleValue(), 0.01)
						case "min":
							assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01)
						case "max":
							assert.InDelta(t, float64(3), dp.DoubleValue(), 0.01)
						}
						_, ok := dp.Attributes().Get("required_string_attr")
						assert.True(t, ok)
						_, ok = dp.Attributes().Get("string_attr")
						assert.False(t, ok)
						_, ok = dp.Attributes().Get("boolean_attr")
						assert.False(t, ok)
					}
				case "system.cpu.time":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["system.cpu.time"], "Found a duplicate in the metrics slice: system.cpu.time")
						validatedMetrics["system.cpu.time"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						assert.Equal(t, int64(1), dp.IntValue())
						cpuAttrVal, ok := dp.Attributes().Get("cpu")
						assert.True(t, ok)
						assert.Equal(t, "cpu-val", cpuAttrVal.Str())
					} else {
						assert.False(t, validatedMetrics["system.cpu.time"], "Found a duplicate in the metrics slice: system.cpu.time")
						validatedMetrics["system.cpu.time"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description())
						assert.Equal(t, "s", mi.Unit())
						assert.True(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						switch aggMap["system.cpu.time"] {
						case "sum":
							assert.Equal(t, int64(4), dp.IntValue())
						case "avg":
							assert.Equal(t, int64(2), dp.IntValue())
						case "min":
							assert.Equal(t, int64(1), dp.IntValue())
						case "max":
							assert.Equal(t, int64(3), dp.IntValue())
						}
						_, ok := dp.Attributes().Get("cpu")
						assert.False(t, ok)
					}
				case "system.memory.usage":
					if tt.name != "reaggregate_set" {
						assert.False(t, validatedMetrics["system.memory.usage"], "Found a duplicate in the metrics slice: system.memory.usage")
						validatedMetrics["system.memory.usage"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Bytes of memory in use.", mi.Description())
						assert.Equal(t, "By", mi.Unit())
						assert.False(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						assert.Equal(t, int64(1), dp.IntValue())
						stateAttrVal, ok := dp.Attributes().Get("state")
						assert.True(t, ok)
						assert.Equal(t, "buffered", stateAttrVal.Str())
					} else {
						assert.False(t, validatedMetrics["system.memory.usage"], "Found a duplicate in the metrics slice: system.memory.usage")
						validatedMetrics["system.memory.usage"] = true
						assert.Equal(t, pmetric.MetricTypeSum, mi.Type())
						assert.Equal(t, 1, mi.Sum().DataPoints().Len())
						assert.Equal(t, "Bytes of memory in use.", mi.Description())
						assert.Equal(t, "By", mi.Unit())
						assert.False(t, mi.Sum().IsMonotonic())
						assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality())
						dp := mi.Sum().DataPoints().At(0)
						assert.Equal(t, start, dp.StartTimestamp())
						assert.Equal(t, ts, dp.Timestamp())
						assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
						switch aggMap["system.memory.usage"] {
						case "sum":
							assert.Equal(t, int64(4), dp.IntValue())
						case "avg":
							assert.Equal(t, int64(2), dp.IntValue())
						case "min":
							assert.Equal(t, int64(1), dp.IntValue())
						case "max":
							assert.Equal(t, int64(3), dp.IntValue())
						}
						_, ok := dp.Attributes().Get("state")
						assert.False(t, ok)
					}
				}
			}
		})
	}
}
