@@ -58,13 +58,27 @@ class RoutesSuite extends CatsEffectSuite:
5858 val tempFile = tempDir / " index.html"
5959 os.write(tempFile, """ <head><title>Test</title></head><body><h1>Test</h1></body>""" )
6060 os.write(tempDir / " index.less" , simpleCss)
61+ os.write(tempDir / " image.webp" , os.read.bytes(os.resource / " cat.webp" ))
6162 tempDir
6263 ,
6364 teardown = tempDir =>
6465 // Always gets called, even if test failed.
6566 os.remove.all(tempDir)
6667 )
6768
69+ val externalIndexR =
70+ ResourceFunFixture {
71+ IO {
72+ val tempDir = os.temp.dir()
73+ // create a file in the folder
74+ val tempFile = tempDir / " index.html"
75+ os.write(tempFile, """ <head><title>Test</title></head><body><h1>Test</h1></body>""" )
76+ os.write(tempDir / " index.less" , simpleCss)
77+ os.write(tempDir / " image.webp" , os.read.bytes(os.resource / " cat.webp" ))
78+ tempDir
79+ }.toResource
80+ }
81+
6882 val externalSyles = FunFixture [os.Path ](
6983 setup = test =>
7084 val tempDir = os.temp.dir()
@@ -358,17 +372,15 @@ class RoutesSuite extends CatsEffectSuite:
358372 }
359373 }
360374
361- externalIndexHtml.test(" Static files are updated when needed and cached otherwise" .only ) {
375+ externalIndexHtml.test(" Static files are updated when needed and cached otherwise" ) {
362376 staticDir =>
363- val cat = os.read.bytes(os.resource / " cat.webp" )
364-
365377 val app = for
366378 logger <- IO (scribe.cats[IO ]).toResource
367379 fileToHashRef <- Ref [IO ].of(Map .empty[String , String ]).toResource
368380 fileToHashMapRef = MapRef .fromSingleImmutableMapRef[IO , String , String ](fileToHashRef)
369381 refreshPub <- Topic [IO , Unit ].toResource
370- _ <- IO .blocking (os.write (staticDir / " image.webp" , cat )).toResource
371- modifedAt <- fileLastModified((staticDir / " index.html " ).toFs2)
382+ _ <- logger.trace (os.stat (staticDir / " image.webp" ).toString( )).toResource
383+ modifedAt <- fileLastModified((staticDir / " image.webp " ).toFs2)
372384 .map {
373385 seconds =>
374386 httpCacheFormat(ZonedDateTime .ofInstant(Instant .ofEpochSecond(seconds), ZoneId .of(" GMT" )))
@@ -406,6 +418,9 @@ class RoutesSuite extends CatsEffectSuite:
406418 // Don't forget to set them _all_
407419 assertIO(served(request1).map(_.status.code), 200 ) >>
408420 assertIO(served(request2).map(_.status.code), 304 ) >>
421+ IO .sleep(
422+ 1500 .millis
423+ ) >>
409424 IO .blocking(os.write.over(staticDir / " image.webp" , os.read.bytes(os.resource / " dog.webp" ))) >>
410425 served(request2).flatMap(_.bodyText.compile.string).flatMap(s => logger.trace(s)) >>
411426 assertIO(served(request2).map(_.status.code), 200 )
0 commit comments