@@ -105,70 +105,91 @@ class ConfigurationApiImplTest extends Specification {
105105
106106 prefix(" /api/v2/ci/tests/skippable" ) {
107107 def requestJson = moshi. adapter(Map ). fromJson(new String (request. body))
108- boolean expectedRequest = requestJson == [
109- " data" : [
110- " type" : " test_params" ,
111- " id" : " 1234" ,
112- " attributes" : [
113- " service" : " foo" ,
114- " env" : " foo_env" ,
115- " repository_url" : " https://github.com/DataDog/foo" ,
116- " branch" : " prod" ,
117- " sha" : " d64185e45d1722ab3a53c45be47accae" ,
118- " test_level" : " test" ,
119- " configurations" : [
120- " os.platform" : " linux" ,
121- " os.architecture" : " amd64" ,
122- " os.arch" : " amd64" ,
123- " os.version" : " bionic" ,
124- " runtime.name" : " runtimeName" ,
125- " runtime.version" : " runtimeVersion" ,
126- " runtime.vendor" : " vendor" ,
127- " runtime.architecture" : " amd64" ,
128- " custom" : [
129- " customTag" : " customValue"
130- ]
131- ]
132- ]
133- ]
134- ]
108+
109+ // assert request contents
110+ def requestData = requestJson[' data' ]
111+ if (requestData[' type' ] != " test_params"
112+ || requestData[' id' ] != " 1234"
113+ ) {
114+ response. status(400 ). send()
115+ return
116+ }
117+
118+ def requestAttrs = requestData[' attributes' ]
119+ if (requestAttrs[' service' ] != " foo"
120+ || requestAttrs[' env' ] != " foo_env"
121+ || requestAttrs[' repository_url' ] != " https://github.com/DataDog/foo"
122+ || requestAttrs[' branch' ] != " prod"
123+ || requestAttrs[' sha' ] != " d64185e45d1722ab3a53c45be47accae"
124+ || requestAttrs[' test_level' ] != " test"
125+ ) {
126+ response. status(400 ). send()
127+ return
128+ }
129+
130+ def requestConfs = requestAttrs[' configurations' ]
131+ if (requestConfs[' os.platform' ] != " linux"
132+ || requestConfs[' os.architecture' ] != " amd64"
133+ || requestConfs[' os.arch' ] != " amd64"
134+ || requestConfs[' os.version' ] != " bionic"
135+ || requestConfs[' runtime.name' ] != " runtimeName"
136+ || requestConfs[' runtime.version' ] != " runtimeVersion"
137+ || requestConfs[' runtime.vendor' ] != " vendor"
138+ || requestConfs[' runtime.architecture' ] != " amd64"
139+ || requestConfs[' custom' ][' customTag' ] != " customValue"
140+ ) {
141+ response. status(400 ). send()
142+ return
143+ }
144+
145+ def moduleATest = """ {
146+ "id": "49968354e2091cdb",
147+ "type": "test",
148+ "attributes": {
149+ "configurations": {
150+ "test.bundle": "testBundle-a",
151+ "custom": {
152+ "customTag": "customValue"
153+ }
154+ },
155+ "suite": "suite-a",
156+ "name": "name-a",
157+ "parameters": "parameters-a",
158+ "_missing_line_code_coverage": true
159+ }
160+ }"""
161+
162+ def moduleBTest = """ {
163+ "id": "49968354e2091cdc",
164+ "type": "test",
165+ "attributes": {
166+ "configurations": {
167+ "test.bundle": "testBundle-b",
168+ "custom": {
169+ "customTag": "customValue"
170+ }
171+ },
172+ "suite": "suite-b",
173+ "name": "name-b",
174+ "parameters": "parameters-b"
175+ }
176+ }"""
177+
178+ def testBundle = requestConfs[' test.bundle' ]
179+
180+ def tests = []
181+ if (! testBundle || testBundle == ' testBundle-a' ) {
182+ tests << moduleATest
183+ }
184+ if (! testBundle || testBundle == ' testBundle-b' ) {
185+ tests << moduleBTest
186+ }
135187
136188 def response = response
137- if (expectedRequest) {
138- def requestBody = """
189+ def requestBody = """
139190{
140191 "data": [
141- {
142- "id": "49968354e2091cdb",
143- "type": "test",
144- "attributes": {
145- "configurations": {
146- "test.bundle": "testBundle-a",
147- "custom": {
148- "customTag": "customValue"
149- }
150- },
151- "suite": "suite-a",
152- "name": "name-a",
153- "parameters": "parameters-a",
154- "_missing_line_code_coverage": true
155- }
156- },
157- {
158- "id": "49968354e2091cdc",
159- "type": "test",
160- "attributes": {
161- "configurations": {
162- "test.bundle": "testBundle-b",
163- "custom": {
164- "customTag": "customValue"
165- }
166- },
167- "suite": "suite-b",
168- "name": "name-b",
169- "parameters": "parameters-b"
170- }
171- }
192+ ${ tests.join(',')}
172193 ],
173194 "meta": {
174195 "correlation_id": "11223344",
@@ -181,17 +202,14 @@ class ConfigurationApiImplTest extends Specification {
181202}
182203""" . bytes
183204
184- def header = request. getHeader(" Accept-Encoding" )
185- def gzipSupported = header != null && header. contains(" gzip" )
186- if (gzipSupported) {
187- response. addHeader(" Content-Encoding" , " gzip" )
188- requestBody = gzip(requestBody)
189- }
190-
191- response. status(200 ). send(requestBody)
192- } else {
193- response. status(400 ). send()
205+ def header = request. getHeader(" Accept-Encoding" )
206+ def gzipSupported = header != null && header. contains(" gzip" )
207+ if (gzipSupported) {
208+ response. addHeader(" Content-Encoding" , " gzip" )
209+ requestBody = gzip(requestBody)
194210 }
211+
212+ response. status(200 ). send(requestBody)
195213 }
196214
197215 prefix(" /api/v2/ci/libraries/tests" ) {
@@ -338,6 +356,22 @@ class ConfigurationApiImplTest extends Specification {
338356 givenIntakeApi(true ) | " intake, compression enabled"
339357 }
340358
359+ def " test skippable tests request with module name" () {
360+ given :
361+ def tracerEnvironment = givenTracerEnvironment(" testBundle-a" )
362+ def metricCollector = Stub (CiVisibilityMetricCollector )
363+ def api = givenIntakeApi(false )
364+
365+ when :
366+ def configurationApi = new ConfigurationApiImpl (api, metricCollector, () -> " 1234" )
367+ def skippableTests = configurationApi. getSkippableTests(tracerEnvironment)
368+
369+ then :
370+ skippableTests. identifiersByModule == [
371+ " testBundle-a" : [ new TestIdentifier (" suite-a" , " name-a" , " parameters-a" ): new TestMetadata (true ), ]
372+ ]
373+ }
374+
341375 private static BitSet bits (int ... bits ) {
342376 BitSet bitSet = new BitSet ()
343377 for (int bit : bits) {
@@ -406,21 +440,22 @@ class ConfigurationApiImplTest extends Specification {
406440 return new IntakeApi (intakeUrl, apiKey, traceId, retryPolicyFactory, client, responseCompression)
407441 }
408442
409- private static TracerEnvironment givenTracerEnvironment () {
443+ private static TracerEnvironment givenTracerEnvironment (String testBundle = null ) {
410444 return TracerEnvironment . builder()
411- .service(" foo" )
412- .env(" foo_env" )
413- .repositoryUrl(" https://github.com/DataDog/foo" )
414- .branch(" prod" )
415- .sha(" d64185e45d1722ab3a53c45be47accae" )
416- .osPlatform(" linux" )
417- .osArchitecture(" amd64" )
418- .osVersion(" bionic" )
419- .runtimeName(" runtimeName" )
420- .runtimeVersion(" runtimeVersion" )
421- .runtimeVendor(" vendor" )
422- .runtimeArchitecture(" amd64" )
423- .customTag(" customTag" , " customValue" )
424- .build()
445+ .service(" foo" )
446+ .env(" foo_env" )
447+ .repositoryUrl(" https://github.com/DataDog/foo" )
448+ .branch(" prod" )
449+ .sha(" d64185e45d1722ab3a53c45be47accae" )
450+ .osPlatform(" linux" )
451+ .osArchitecture(" amd64" )
452+ .osVersion(" bionic" )
453+ .runtimeName(" runtimeName" )
454+ .runtimeVersion(" runtimeVersion" )
455+ .runtimeVendor(" vendor" )
456+ .runtimeArchitecture(" amd64" )
457+ .customTag(" customTag" , " customValue" )
458+ .testBundle(testBundle)
459+ .build()
425460 }
426461}
0 commit comments