-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from craigatk/compression
(feature) Adding support for compressing JSON and JS responses from server
- Loading branch information
Showing
4 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import java.util.zip.GZIPInputStream | ||
|
||
fun ungzip(content: ByteArray): String = | ||
GZIPInputStream(content.inputStream()).bufferedReader(Charsets.UTF_8).use { it.readText() } |
64 changes: 64 additions & 0 deletions
64
server/server-app/src/test/kotlin/projektor/testrun/GetTestRunCompressionApplicationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package projektor.testrun | ||
|
||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.testing.handleRequest | ||
import io.ktor.server.testing.withTestApplication | ||
import io.ktor.util.KtorExperimentalAPI | ||
import kotlin.test.assertNotNull | ||
import org.junit.jupiter.api.Test | ||
import projektor.ApplicationTestCase | ||
import projektor.TestSuiteData | ||
import projektor.incomingresults.randomPublicId | ||
import projektor.server.api.TestRun | ||
import strikt.api.expectThat | ||
import strikt.assertions.hasSize | ||
import strikt.assertions.isEqualTo | ||
import ungzip | ||
|
||
@KtorExperimentalAPI | ||
class GetTestRunCompressionApplicationTest : ApplicationTestCase() { | ||
@Test | ||
fun `when gzip accept header included should compress test run response`() { | ||
val publicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId") { | ||
testRunDBGenerator.createTestRun( | ||
publicId, | ||
listOf( | ||
TestSuiteData("testSuite1", | ||
listOf("testSuite1TestCase1", "testSuite1TestCase2"), | ||
listOf(), | ||
listOf() | ||
), | ||
TestSuiteData("testSuite2", | ||
listOf("testSuite2TestCase1", "testSuite2TestCase2", "testSuite2TestCase3"), | ||
listOf(), | ||
listOf() | ||
) | ||
) | ||
) | ||
|
||
addHeader(HttpHeaders.AcceptEncoding, "gzip") | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
|
||
val responseBytes = response.byteContent | ||
assertNotNull(responseBytes) | ||
|
||
val uncompressedResponse = ungzip(responseBytes) | ||
|
||
val responseRun = objectMapper.readValue(uncompressedResponse, TestRun::class.java) | ||
assertNotNull(responseRun) | ||
|
||
expectThat(responseRun.id).isEqualTo(publicId.id) | ||
|
||
val testSuites = responseRun.testSuites | ||
assertNotNull(testSuites) | ||
expectThat(testSuites).hasSize(2) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters