Skip to content

Commit 22aab0a

Browse files
committed
Revamped Mongo comment tests
1 parent af21356 commit 22aab0a

File tree

2 files changed

+51
-273
lines changed

2 files changed

+51
-273
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

dd-java-agent/instrumentation/mongo/driver-4.0/src/test/groovy/MongoDBMInjectionTest.groovy

Lines changed: 0 additions & 273 deletions
This file was deleted.

0 commit comments

Comments
 (0)