summaryrefslogblamecommitdiff
path: root/example/compress3/app/test/src/ExampleTests.scala
blob: 2bd8b31cbefee2aa489f9ed7c0e3960db5cbe945 (plain) (tree)
1
2
3
4
5
6
7





                                      
                                                                   











                                         
                                                              

                                                             
                                                                            
             
                                           




       
package app
import io.undertow.Undertow

import utest._

object ExampleTests extends TestSuite{
  def withServer[T](example: cask.main.Main)(f: String => T): T = {
    val server = Undertow.builder
      .addHttpListener(8080, "localhost")
      .setHandler(example.defaultHandler)
      .build
    server.start()
    val res =
      try f("http://localhost:8080")
      finally server.stop()
    res
  }

  val tests = Tests{
    test("Compress3Main") - withServer(Compress3Main){ host =>
      val expected = "Hello World! Hello World! Hello World!"
      requests.get(s"$host").text() ==> expected
      val compressed = requests.get(s"$host", autoDecompress = false).text()
      assert(
        compressed.length < expected.length
      )

    }
  }
}