MCPcopy
hub / github.com/grafana/tempo / TestNewBinaryOperation_TraceIDNormalization

Function TestNewBinaryOperation_TraceIDNormalization

pkg/traceql/ast_test.go:1170–1232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1168}
1169
1170func TestNewBinaryOperation_TraceIDNormalization(t *testing.T) {
1171 traceIDAttr := NewIntrinsic(IntrinsicTraceID)
1172 op := OpEqual
1173
1174 tests := []struct {
1175 name string
1176 expression FieldExpression
1177 expected FieldExpression
1178 }{
1179 {
1180 name: "with leading zeros",
1181 expression: NewStaticString("0000123"),
1182 expected: NewStaticString("123"),
1183 },
1184 {
1185 name: "no leading zeros",
1186 expression: NewStaticString("123456789abcdef123456789abcdef"),
1187 expected: NewStaticString("123456789abcdef123456789abcdef"),
1188 },
1189 {
1190 name: "int",
1191 expression: NewStaticInt(123),
1192 expected: NewStaticInt(123),
1193 },
1194 {
1195 name: "float",
1196 expression: NewStaticFloat(123.0),
1197 expected: NewStaticFloat(123.0),
1198 },
1199 }
1200
1201 for _, tc := range []struct {
1202 name string
1203 reverse bool
1204 }{
1205 {name: "trace:id = value", reverse: false},
1206 {name: "value = trace:id", reverse: true},
1207 } {
1208 for _, tt := range tests {
1209 t.Run(tc.name+" "+tt.name, func(t *testing.T) {
1210 var lhs FieldExpression = traceIDAttr
1211 rhs := tt.expression
1212 var expectedLHS FieldExpression = traceIDAttr
1213 expectedRHS := tt.expected
1214
1215 if tc.reverse {
1216 lhs = tt.expression
1217 rhs = traceIDAttr
1218 expectedLHS = tt.expected
1219 expectedRHS = traceIDAttr
1220 }
1221
1222 binop := newBinaryOperation(op, lhs, rhs)
1223
1224 // Verify the result is a BinaryOperation
1225 require.IsType(t, &BinaryOperation{}, binop)
1226 actualBinop := binop.(*BinaryOperation)
1227 assert.Equal(t, expectedLHS, actualBinop.LHS)

Callers

nothing calls this directly

Calls 7

NewIntrinsicFunction · 0.85
NewStaticStringFunction · 0.85
NewStaticIntFunction · 0.85
NewStaticFloatFunction · 0.85
newBinaryOperationFunction · 0.85
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected