8
8
"time"
9
9
10
10
"github.com/kubeshop/tracetest/server/expression"
11
+ "github.com/kubeshop/tracetest/server/pkg/id"
11
12
"github.com/kubeshop/tracetest/server/traces"
12
13
"github.com/kubeshop/tracetest/server/variableset"
13
14
"github.com/stretchr/testify/assert"
@@ -103,6 +104,7 @@ func TestAttributeExecution(t *testing.T) {
103
104
104
105
AttributeDataStore : expression.AttributeDataStore {
105
106
Span : traces.Span {
107
+ ID : id .NewRandGenerator ().SpanID (),
106
108
Attributes : traces .NewAttributes (map [string ]string {
107
109
"my_attribute" : "42" ,
108
110
}),
@@ -116,12 +118,39 @@ func TestAttributeExecution(t *testing.T) {
116
118
117
119
AttributeDataStore : expression.AttributeDataStore {
118
120
Span : traces.Span {
121
+ ID : id .NewRandGenerator ().SpanID (),
119
122
Attributes : traces .NewAttributes (map [string ]string {
120
123
"dapr-app-id" : "42" ,
121
124
}),
122
125
},
123
126
},
124
127
},
128
+ {
129
+ Name : "should_return_error_when_attribute_doesnt_exist" ,
130
+ Query : "attr:dapr-app-id = 43" ,
131
+ ShouldPass : false ,
132
+ ExpectedErrorMessage : `resolution error: attribute "dapr-app-id" not found` ,
133
+
134
+ AttributeDataStore : expression.AttributeDataStore {
135
+ Span : traces.Span {
136
+ ID : id .NewRandGenerator ().SpanID (),
137
+ },
138
+ },
139
+ },
140
+ {
141
+ Name : "should_return_error_when_no_matching_spans" ,
142
+ Query : "attr:dapr-app-id = 42" ,
143
+ ShouldPass : false ,
144
+ ExpectedErrorMessage : `resolution error: there are no matching spans to retrieve the attribute "dapr-app-id" from. To fix this error, create a selector matching at least one span.` ,
145
+
146
+ AttributeDataStore : expression.AttributeDataStore {
147
+ Span : traces.Span {
148
+ // An span without an id is an invalid span
149
+ // this is the value received when we don't have any matching
150
+ // spans in the assertion.
151
+ },
152
+ },
153
+ },
125
154
}
126
155
127
156
executeTestCases (t , testCases )
@@ -135,6 +164,7 @@ func TestStringInterpolationExecution(t *testing.T) {
135
164
ShouldPass : true ,
136
165
AttributeDataStore : expression.AttributeDataStore {
137
166
Span : traces.Span {
167
+ ID : id .NewRandGenerator ().SpanID (),
138
168
Attributes : traces .NewAttributes (map [string ]string {
139
169
"text" : "this run took 25ms" ,
140
170
}),
@@ -159,6 +189,7 @@ func TestFilterExecution(t *testing.T) {
159
189
ShouldPass : true ,
160
190
AttributeDataStore : expression.AttributeDataStore {
161
191
Span : traces.Span {
192
+ ID : id .NewRandGenerator ().SpanID (),
162
193
Attributes : traces .NewAttributes (map [string ]string {
163
194
"tracetest.response.body" : `{"id": 8, "name": "john doe"}` ,
164
195
}),
@@ -345,6 +376,9 @@ func executeTestCases(t *testing.T, testCases []executorTestCase) {
345
376
assert .NoError (t , err , debugMessage )
346
377
} else {
347
378
assert .Error (t , err , debugMessage )
379
+ if testCase .ExpectedErrorMessage != "" {
380
+ assert .Equal (t , testCase .ExpectedErrorMessage , err .Error ())
381
+ }
348
382
}
349
383
})
350
384
}
@@ -376,6 +410,7 @@ func TestResolveStatementAttributeExecution(t *testing.T) {
376
410
377
411
AttributeDataStore : expression.AttributeDataStore {
378
412
Span : traces.Span {
413
+ ID : id .NewRandGenerator ().SpanID (),
379
414
Attributes : traces .NewAttributes (map [string ]string {
380
415
"my_attribute" : "42" ,
381
416
}),
@@ -395,6 +430,7 @@ func TestResolveStatementStringInterpolationExecution(t *testing.T) {
395
430
ShouldPass : true ,
396
431
AttributeDataStore : expression.AttributeDataStore {
397
432
Span : traces.Span {
433
+ ID : id .NewRandGenerator ().SpanID (),
398
434
Attributes : traces .NewAttributes (map [string ]string {
399
435
"text" : "this run took 25ms" ,
400
436
}),
@@ -419,6 +455,7 @@ func TestResolveStatementFilterExecution(t *testing.T) {
419
455
ShouldPass : true ,
420
456
AttributeDataStore : expression.AttributeDataStore {
421
457
Span : traces.Span {
458
+ ID : id .NewRandGenerator ().SpanID (),
422
459
Attributes : traces .NewAttributes (map [string ]string {
423
460
"tracetest.response.body" : `{"id": 8, "name": "john doe"}` ,
424
461
}),
@@ -480,6 +517,7 @@ func TestFailureCases(t *testing.T) {
480
517
481
518
AttributeDataStore : expression.AttributeDataStore {
482
519
Span : traces.Span {
520
+ ID : id .NewRandGenerator ().SpanID (),
483
521
Attributes : traces .NewAttributes (map [string ]string {
484
522
"attr1" : "1" ,
485
523
"attr2" : "2" ,
0 commit comments