Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Dec 30, 2024
1 parent 957874e commit e4172a4
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

import java.io.ByteArrayInputStream
import java.util.zip.GZIPInputStream
import java.nio.file.Files
import java.io.File
import java.io.FileInputStream

class GZIPCompressingInputStreamTest extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks {
implicit override val generatorDrivenConfig =
Expand All @@ -18,4 +21,21 @@ class GZIPCompressingInputStreamTest extends AnyFlatSpec with Matchers with Scal
decompressed shouldEqual input
}
}

it should "compress data from a file" in {
val testFileContent = "test file content"
withTemporaryFile(testFileContent.getBytes()) { file =>
val gzipInputStream = new GZIPInputStream(new GZIPCompressingInputStream(new FileInputStream(file)))
val decompressedBytes = gzipInputStream.readAllBytes()
decompressedBytes shouldEqual testFileContent.getBytes()
}
}

private def withTemporaryFile[T](content: Array[Byte])(f: File => T): T = {
val file = Files.createTempFile("sttp", "sttp")
Files.write(file, content)

try f(file.toFile)
finally { val _ = Files.deleteIfExists(file) }
}
}

0 comments on commit e4172a4

Please sign in to comment.