Files
traces/pkg/api/dedicated_columns_to_json_test.go
A. StoewerandGitHub 5047a53e44 vParquet5: dedicated columns for int values (#5639)
* Add dedicated column type INT to tempopb

* Add int dedicated columns to vp5 schema

* Rename version to vparquet5-preview2

* Use iterators and range loops to iterate over dedicatedColumns

* Re-generate test-data

* CHANGELOG.md

* Tests with dedicated columns have int types
2025-09-16 07:28:16 +10:00

71 lines
1.5 KiB
Go

package api
import (
"encoding/json"
"math/rand/v2"
"testing"
"github.com/grafana/tempo/pkg/util/test"
"github.com/grafana/tempo/tempodb/backend"
"github.com/stretchr/testify/require"
)
func TestDedicatedColumnsToJson(t *testing.T) {
d := NewDedicatedColumnsToJSON()
testCols := []backend.DedicatedColumns{}
for i := 0; i < 10; i++ {
testCols = append(testCols, randoDedicatedCols())
}
// do all test cols 2x to test caching
for i := 0; i < 2; i++ {
for _, cols := range testCols {
expectedJSON := dedicatedColsToJSON(t, cols)
actualJSON, err := d.JSONForDedicatedColumns(cols)
require.NoError(t, err)
require.Equal(t, expectedJSON, actualJSON, "iteration %d, cols: %v", i, cols)
}
}
}
func dedicatedColsToJSON(t *testing.T, cols backend.DedicatedColumns) string {
t.Helper()
proto, err := cols.ToTempopb()
require.NoError(t, err)
jsonBytes, err := json.Marshal(proto)
require.NoError(t, err)
return string(jsonBytes)
}
// randoDedicatedCols generates a random set of cols for testing
func randoDedicatedCols() backend.DedicatedColumns {
colCount := rand.IntN(5) + 1
ret := make([]backend.DedicatedColumn, 0, colCount)
for i := 0; i < colCount; i++ {
scope := backend.DedicatedColumnScopeSpan
if rand.IntN(2) == 0 {
scope = backend.DedicatedColumnScopeResource
}
typ := backend.DedicatedColumnTypeString
if rand.IntN(2) == 0 {
typ = backend.DedicatedColumnTypeInt
}
col := backend.DedicatedColumn{
Scope: scope,
Name: test.RandomString(),
Type: typ,
}
ret = append(ret, col)
}
return ret
}