diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-15 16:18:01 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-20 20:03:30 +0000 |
commit | a8fdb0fc9d296db66ddd5cf14c88023e9bd9a364 (patch) | |
tree | 9439c50824f6d7bcd5de3451841bfeb448e13d3c /sonar-scanner-engine/src/test/java | |
parent | 1731498e4f43bee8fc3c57ea58b1985db352baea (diff) | |
download | sonarqube-a8fdb0fc9d296db66ddd5cf14c88023e9bd9a364.tar.gz sonarqube-a8fdb0fc9d296db66ddd5cf14c88023e9bd9a364.zip |
SONAR-17337 Scanner download of analyzer cache doesn't handle compression correctly
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java index 4f666a58a53..3147eadbb8c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java @@ -27,6 +27,8 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.zip.DeflaterInputStream; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -130,7 +132,7 @@ public class DefaultAnalysisCacheLoaderTest { } private void setCompressedResponse(AnalysisCacheMsg msg) throws IOException { - when(response.contentStream()).thenReturn(new DeflaterInputStream(createInputStream(msg))); + when(response.contentStream()).thenReturn(createCompressedInputStream(msg)); when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip")); } @@ -144,4 +146,12 @@ public class DefaultAnalysisCacheLoaderTest { analysisCacheMsg.writeTo(serialized); return new ByteArrayInputStream(serialized.toByteArray()); } + + private InputStream createCompressedInputStream(AnalysisCacheMsg analysisCacheMsg) throws IOException { + ByteArrayOutputStream serialized = new ByteArrayOutputStream(analysisCacheMsg.getSerializedSize()); + GZIPOutputStream compressed = new GZIPOutputStream(serialized); + analysisCacheMsg.writeTo(compressed); + compressed.close(); + return new ByteArrayInputStream(serialized.toByteArray()); + } } |