From e9049436e620f8ba34465a0d68be06472ee720b6 Mon Sep 17 00:00:00 2001 From: Jack Dockerty Date: Fri, 12 Jan 2024 16:55:20 +0000 Subject: [PATCH] feat: expand test cases --- tsdb/series_cursor.go | 2 +- tsdb/series_file_test.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tsdb/series_cursor.go b/tsdb/series_cursor.go index f2998bce38a..14d84d5c73c 100644 --- a/tsdb/series_cursor.go +++ b/tsdb/series_cursor.go @@ -114,7 +114,7 @@ func (cur *seriesCursor) Next() (*SeriesCursorRow, error) { cur.row.Name, cur.row.Tags = ParseSeriesKey(cur.keys[cur.ofs]) if cur.row.Name == nil && cur.row.Tags == nil { - return nil, fmt.Errorf("series key was not valid: %s", cur.keys[cur.ofs]) + return nil, fmt.Errorf("series key was not valid: %+v", cur.keys[cur.ofs]) } cur.ofs++ diff --git a/tsdb/series_file_test.go b/tsdb/series_file_test.go index 0febe029ba8..11184455092 100644 --- a/tsdb/series_file_test.go +++ b/tsdb/series_file_test.go @@ -54,12 +54,18 @@ func TestParseSeriesKeyMeasurement(t *testing.T) { tests := []struct { name string measurement []byte + expected []byte }{ - {name: "invalid measurement", measurement: []byte{}}, + {name: "invalid measurement", measurement: tsdb.AppendSeriesKey(nil, []byte{}, nil), expected: nil}, + {name: "valid measurement", measurement: tsdb.AppendSeriesKey(nil, []byte("cpu"), nil), expected: []byte("cpu")}, } for _, tt := range tests { - tsdb.ParseSeriesKey(tt.measurement) + name, _ := tsdb.ParseSeriesKey(tt.measurement) + if res := bytes.Compare(name, tt.expected); res != 0 { + t.Fatalf("invalid series key parse: got %q, expected %q", name, tt.expected) + } + } }