Repository: prometheus/prometheus
File: tsdb/agent/db_test.go (Go)

Code before:
		expectedSampleCount int
		expectedType        string
		expectedErrorMsg    string
	}{
		{
			name: "Float samples",
			appendFunc: func(app storage.Appender, lset labels.Labels, t, ct int64, value interface{}) (storage.SeriesRef, error) {
				ref, err := app.AppendCTZeroSample(0, lset, t, ct)
				if err != nil {
					return 0, err
				}
				_, err = app.Append(0, lset, t, value.(float64))
				return ref, err
			},
			appendErrorFunc: func(app storage.Appender, ref storage.SeriesRef, lset labels.Labels, t, ct int64, value interface{}) error {
				_, err := app.AppendCTZeroSample(ref, lset, t, ct)
				return err
			},
			value:               float64(20),
			expectedSampleCount: 2,
			expectedType:        "float",
			expectedErrorMsg:    "CT is newer or the same as sample's timestamp, ignoring",
		},
		{
			name: "Histogram samples",
			appendFunc: func(app storage.Appender, lset labels.Labels, t, ct int64, value interface{}) (storage.SeriesRef, error) {
				ref, err := app.AppendHistogramCTZeroSample(0, lset, t, ct, &histogram.Histogram{}, nil)
				if err != nil {
					return 0, err
				}
				_, err = app.AppendHistogram(0, lset, t, value.(*histogram.Histogram), nil)
				return ref, err
			},
			appendErrorFunc: func(app storage.Appender, ref storage.SeriesRef, lset labels.Labels, t, ct int64, value interface{}) error {
				_, err := app.AppendHistogramCTZeroSample(ref, lset, t, ct, value.(*histogram.Histogram), nil)
				return err
			},
			value:               tsdbutil.GenerateTestHistograms(1)[0],
			expectedSampleCount: 2,
			expectedType:        "histogram",
			expectedErrorMsg:    storage.ErrCTNewerThanSample.Error(),
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			reg := prometheus.NewRegistry()
			opts := DefaultOptions()
			opts.OutOfOrderTimeWindow = 0
			s := createTestAgentDB(t, reg, opts)
			app := s.Appender(context.TODO())

Review comment (suggestion):
The idea of table testing is to have several input data that go through the same logic and we compare the expected result. If we're having different append logic depending on the input, I guess it goes against the purpose 😬 

[TestHeadAppender_AppendCT](https://github.com/prometheus/prometheus/blob/2cabd1b707b0569f65fbc2bafa899cabf47cfe09/tsdb/head_test.go#L6283-L6502) is a good example to take inspiration from, we just need to change how we compare the results without a querier

Code after:
	ref  storage.SeriesRef
}

func TestDBCreatedTimestampSamplesIngestion(t *testing.T) {
	t.Parallel()

	type appendableSample struct {
		t            int64
		ct           int64
		v            float64
		lbls         labels.Labels
		h            *histogram.Histogram
		expectsError bool
	}

	testHistogram := tsdbutil.GenerateTestHistograms(1)[0]
	zeroHistogram := &histogram.Histogram{}

	lbls := labelsForTest(t.Name(), 1)
	defLbls := labels.New(lbls[0]...)

	testCases := []struct {
		name                string
		inputSamples        []appendableSample
		expectedSamples     []*walSample
		expectedSeriesCount int
	}{
		{
			name: "in order ct+normal sample/floatSamples",
			inputSamples: []appendableSample{
				{t: 100, ct: 1, v: 10, lbls: defLbls},
				{t: 101, ct: 1, v: 10, lbls: defLbls},
			},
			expectedSamples: []*walSample{
				{t: 1, f: 0, lbls: defLbls},
				{t: 100, f: 10, lbls: defLbls},
				{t: 101, f: 10, lbls: defLbls},
			},
		},
		{
			name: "CT+float && CT+histogram samples",
			inputSamples: []appendableSample{
				{
					t:    100,
					ct:   30,
					v:    20,
					lbls: defLbls,
				},
				{
					t:    300,
					ct:   230,