File tree Expand file tree Collapse file tree 2 files changed +51
-273
lines changed
dd-java-agent/instrumentation/mongo/driver-4.0/src/test/groovy Expand file tree Collapse file tree 2 files changed +51
-273
lines changed Original file line number Diff line number Diff line change
1
+ import datadog.trace.core.database.SharedDBCommenter
2
+ import spock.lang.Specification
3
+
4
+ class MongoDBMCommentTest extends Specification {
5
+ def " SharedDBCommenter builds MongoDB comment correctly" () {
6
+ when :
7
+ String comment = SharedDBCommenter . buildComment(
8
+ " test-mongo-service" ,
9
+ " mongo" ,
10
+ " localhost" ,
11
+ " testdb" ,
12
+ " 00-1234567890abcdef1234567890abcdef-1234567890abcdef-01"
13
+ )
14
+
15
+ then :
16
+ comment != null
17
+ comment. contains(" ddps='" )
18
+ comment. contains(" dddbs='test-mongo-service'" )
19
+ comment. contains(" ddh='localhost'" )
20
+ comment. contains(" dddb='testdb'" )
21
+ comment. contains(" traceparent='00-1234567890abcdef1234567890abcdef-1234567890abcdef-01'" )
22
+ }
23
+
24
+ def " SharedDBCommenter detects existing trace comments" () {
25
+ given :
26
+ String existingComment = " ddps='service1',dddbs='mongo-service',ddh='host'"
27
+
28
+ expect :
29
+ SharedDBCommenter . containsTraceComment(existingComment) == true
30
+ SharedDBCommenter . containsTraceComment(" some other comment" ) == false
31
+ SharedDBCommenter . containsTraceComment(" " ) == false
32
+ }
33
+
34
+ def " SharedDBCommenter with valid values produces expected comment format" () {
35
+ when :
36
+ String comment = SharedDBCommenter . buildComment(
37
+ " test-service" ,
38
+ " mongo" ,
39
+ " test-host" ,
40
+ " test-db" ,
41
+ " 00-test-trace-test-span-01"
42
+ )
43
+
44
+ then :
45
+ comment != null
46
+ comment. contains(" dddbs='test-service'" )
47
+ comment. contains(" ddh='test-host'" )
48
+ comment. contains(" dddb='test-db'" )
49
+ comment. contains(" traceparent='00-test-trace-test-span-01'" )
50
+ }
51
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments