Skip to content

Commit 9f7f944

Browse files
committed
improve test coverage
1 parent 4a980f7 commit 9f7f944

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package datadog.trace.bootstrap.instrumentation.api
2+
3+
import datadog.context.Context
4+
import spock.lang.Specification
5+
6+
class InferredProxyContextTest extends Specification {
7+
8+
def "test context validity"() {
9+
setup:
10+
def context = new InferredProxyContext()
11+
12+
expect:
13+
!context.validContext()
14+
15+
when:
16+
context.setProxyName("aws.apigateway")
17+
context.setStartTime("123")
18+
context.setDomainName("example.com")
19+
context.setHttpMethod("GET")
20+
context.setPath("/foo")
21+
22+
then:
23+
!context.validContext()
24+
25+
when:
26+
context.setStage("prod")
27+
28+
then:
29+
context.validContext()
30+
}
31+
32+
def "test fromContext and storeInto"() {
33+
setup:
34+
def inferredProxyContext = new InferredProxyContext()
35+
inferredProxyContext.setProxyName("aws.apigateway")
36+
inferredProxyContext.setStartTime("123")
37+
inferredProxyContext.setDomainName("example.com")
38+
inferredProxyContext.setHttpMethod("GET")
39+
inferredProxyContext.setPath("/foo")
40+
inferredProxyContext.setStage("prod")
41+
42+
when:
43+
def context = inferredProxyContext.storeInto(Context.root())
44+
def extractedContext = InferredProxyContext.fromContext(context)
45+
46+
then:
47+
extractedContext == inferredProxyContext
48+
extractedContext.getProxyName() == "aws.apigateway"
49+
}
50+
51+
def "test fromContext with no inferred proxy context"() {
52+
when:
53+
def extractedContext = InferredProxyContext.fromContext(Context.root())
54+
55+
then:
56+
extractedContext == null
57+
}
58+
59+
def "test getters and setters"() {
60+
setup:
61+
def context = new InferredProxyContext()
62+
63+
when:
64+
context.setProxyName("aws.apigateway")
65+
context.setStartTime("123")
66+
context.setDomainName("example.com")
67+
context.setHttpMethod("GET")
68+
context.setPath("/foo")
69+
context.setStage("prod")
70+
71+
then:
72+
context.getProxyName() == "aws.apigateway"
73+
context.getStartTime() == "123"
74+
context.getDomainName() == "example.com"
75+
context.getHttpMethod() == "GET"
76+
context.getPath() == "/foo"
77+
context.getStage() == "prod"
78+
}
79+
80+
def "test context validity for each field"() {
81+
given:
82+
def context = new InferredProxyContext()
83+
84+
when:
85+
if (proxyName) context.setProxyName("proxy")
86+
if (startTime) context.setStartTime("123")
87+
if (domainName) context.setDomainName("domain")
88+
if (httpMethod) context.setHttpMethod("GET")
89+
if (path) context.setPath("/path")
90+
if (stage) context.setStage("prod")
91+
92+
then:
93+
context.validContext() == expected
94+
95+
where:
96+
proxyName | startTime | domainName | httpMethod | path | stage | expected
97+
false | true | true | true | true | true | false
98+
true | false | true | true | true | true | false
99+
true | true | false | true | true | true | false
100+
true | true | true | false | true | true | false
101+
true | true | true | true | false | true | false
102+
true | true | true | true | true | false | false
103+
true | true | true | true | true | true | true
104+
}
105+
}

0 commit comments

Comments
 (0)