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

Function TestUnaryOperation_extractConditions

pkg/traceql/ast_conditions_test.go:422–482  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

420}
421
422func TestUnaryOperation_extractConditions(t *testing.T) {
423 tests := []struct {
424 query string
425 conditions []Condition
426 allConditions bool
427 }{
428 {
429 query: `{ span.foo != nil }`,
430 conditions: []Condition{
431 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "foo"), OpExists),
432 },
433 allConditions: true,
434 },
435 {
436 query: `{ span.foo = nil }`,
437 conditions: []Condition{
438 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "foo"), OpNotExists),
439 },
440 allConditions: true,
441 },
442 {
443 query: `{ span.foo }`,
444 conditions: []Condition{
445 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "foo"), OpNone),
446 },
447 allConditions: true,
448 },
449 {
450 query: `{ !span.foo }`,
451 conditions: []Condition{
452 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "foo"), OpNone),
453 },
454 allConditions: true,
455 },
456 {
457 query: `{ !(span.a = "a" || span.a = "c") }`,
458 conditions: []Condition{
459 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "a"), OpEqual, NewStaticString("a")),
460 newCondition(NewScopedAttribute(AttributeScopeSpan, false, "a"), OpEqual, NewStaticString("c")),
461 },
462 allConditions: false,
463 },
464 }
465
466 for _, tt := range tests {
467 t.Run(tt.query, func(t *testing.T) {
468 expr, err := Parse(tt.query)
469 require.NoError(t, err)
470
471 req := &FetchSpansRequest{
472 Conditions: []Condition{},
473 AllConditions: true,
474 }
475 expr.extractConditions(req)
476
477 assert.Equal(t, tt.conditions, req.Conditions)
478 assert.Nil(t, req.SecondPassConditions)
479 assert.Equal(t, tt.allConditions, req.AllConditions, "FetchSpansRequest.AllConditions")

Callers

nothing calls this directly

Calls 7

newConditionFunction · 0.85
NewScopedAttributeFunction · 0.85
NewStaticStringFunction · 0.85
ParseFunction · 0.85
extractConditionsMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected