(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func TestSelect_extractConditions(t *testing.T) { |
| 255 | tests := []struct { |
| 256 | query string |
| 257 | conditions []Condition |
| 258 | secondPassConditions []Condition |
| 259 | allConditions bool |
| 260 | }{ |
| 261 | { |
| 262 | query: `{ .foo = "a" } | select(resource.service.name)`, |
| 263 | conditions: []Condition{ |
| 264 | newCondition(NewAttribute("foo"), OpEqual, NewStaticString("a")), |
| 265 | }, |
| 266 | secondPassConditions: []Condition{ |
| 267 | newCondition(NewScopedAttribute(AttributeScopeResource, false, "service.name"), OpNone), |
| 268 | }, |
| 269 | allConditions: true, |
| 270 | }, |
| 271 | { |
| 272 | query: `{ } | select(.name,name)`, |
| 273 | conditions: []Condition{ |
| 274 | newCondition(NewIntrinsic(IntrinsicSpanStartTime), OpNone), |
| 275 | }, |
| 276 | secondPassConditions: []Condition{ |
| 277 | newCondition(NewAttribute("name"), OpNone), |
| 278 | newCondition(NewIntrinsic(IntrinsicName), OpNone), |
| 279 | }, |
| 280 | allConditions: true, |
| 281 | }, |
| 282 | { |
| 283 | // Pipleline elements after a select are always directed to the second pass |
| 284 | query: `{ } | select(span.foo) | { span.foo = "a" && span.bar = "b"}`, |
| 285 | conditions: []Condition{ |
| 286 | newCondition(NewIntrinsic(IntrinsicSpanStartTime), OpNone), |
| 287 | }, |
| 288 | secondPassConditions: []Condition{ |
| 289 | // span.foo=a has no effect because it's already covered by the select statement |
| 290 | newCondition(NewScopedAttribute(AttributeScopeSpan, false, "foo"), OpNone), |
| 291 | newCondition(NewScopedAttribute(AttributeScopeSpan, false, "bar"), OpEqual, NewStaticString("b")), |
| 292 | }, |
| 293 | allConditions: true, |
| 294 | }, |
| 295 | } |
| 296 | for _, tt := range tests { |
| 297 | t.Run(tt.query, func(t *testing.T) { |
| 298 | expr, err := Parse(tt.query) |
| 299 | require.NoError(t, err) |
| 300 | |
| 301 | req := &FetchSpansRequest{ |
| 302 | Conditions: []Condition{}, |
| 303 | AllConditions: true, |
| 304 | } |
| 305 | expr.Pipeline.extractConditions(req) |
| 306 | |
| 307 | assert.Equal(t, tt.conditions, req.Conditions) |
| 308 | assert.Equal(t, tt.secondPassConditions, req.SecondPassConditions) |
| 309 | assert.Equal(t, tt.allConditions, req.AllConditions, "FetchSpansRequest.AllConditions") |
| 310 | }) |
| 311 | } |
nothing calls this directly
no test coverage detected