1
1
package org .scalasteward .core .repocache
2
2
3
- import cats .implicits . toSemigroupKOps
3
+ import cats .syntax . all . *
4
4
import io .circe .syntax .*
5
+ import java .time .LocalDateTime
5
6
import munit .CatsEffectSuite
6
7
import org .http4s .HttpApp
7
8
import org .http4s .circe .*
@@ -14,7 +15,9 @@ import org.scalasteward.core.forge.github.Repository
14
15
import org .scalasteward .core .git .Branch
15
16
import org .scalasteward .core .mock .MockContext .context .{repoCacheAlg , repoConfigAlg , workspaceAlg }
16
17
import org .scalasteward .core .mock .{GitHubAuth , MockEff , MockEffOps , MockState }
17
- import org .scalasteward .core .util .intellijThisImportIsUsed
18
+ import org .scalasteward .core .repoconfig .RepoConfig
19
+ import org .scalasteward .core .util .{intellijThisImportIsUsed , Timestamp }
20
+ import scala .concurrent .duration .*
18
21
19
22
class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl [MockEff ] {
20
23
intellijThisImportIsUsed(encodeUri)
@@ -36,7 +39,8 @@ class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
36
39
uri " https://github.com/scala-steward/cats-effect.git " ,
37
40
Branch (" main" )
38
41
)
39
- val repoCache = RepoCache (dummySha1, Nil , None , None )
42
+ val now = Timestamp .fromLocalDateTime(LocalDateTime .now())
43
+ val repoCache = RepoCache (dummySha1, now, Nil , None , None )
40
44
val workspace = workspaceAlg.rootDir.unsafeRunSync()
41
45
val httpApp = HttpApp [MockEff ] {
42
46
case POST -> Root / " repos" / " typelevel" / " cats-effect" / " forks" =>
@@ -55,4 +59,33 @@ class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
55
59
val expected = (RepoData (repo, repoCache, repoConfigAlg.mergeWithGlobal(None )), repoOut)
56
60
assertIO(obtained, expected)
57
61
}
62
+
63
+ test(" throwIfAbandoned: no maxAge" ) {
64
+ val repo = Repo (" repo-cache-alg" , " test-1" )
65
+ val cache = RepoCache (dummySha1, Timestamp (0L ), Nil , None , None )
66
+ val config = RepoConfig .empty
67
+ val data = RepoData (repo, cache, config)
68
+ val obtained = repoCacheAlg.throwIfAbandoned(data).runA(MockState .empty).attempt
69
+ assertIO(obtained, Right (()))
70
+ }
71
+
72
+ test(" throwIfAbandoned: lastCommit < maxAge" ) {
73
+ val repo = Repo (" repo-cache-alg" , " test-2" )
74
+ val commitDate = Timestamp .fromLocalDateTime(LocalDateTime .now())
75
+ val cache = RepoCache (dummySha1, commitDate, Nil , None , None )
76
+ val config = RepoConfig (lastCommitMaxAge = Some (1 .day))
77
+ val data = RepoData (repo, cache, config)
78
+ val obtained = repoCacheAlg.throwIfAbandoned(data).runA(MockState .empty).attempt
79
+ assertIO(obtained, Right (()))
80
+ }
81
+
82
+ test(" throwIfAbandoned: lastCommit > maxAge" ) {
83
+ val repo = Repo (" repo-cache-alg" , " test-3" )
84
+ val cache = RepoCache (dummySha1, Timestamp (0L ), Nil , None , None )
85
+ val config = RepoConfig (lastCommitMaxAge = Some (1 .day))
86
+ val data = RepoData (repo, cache, config)
87
+ val obtained =
88
+ repoCacheAlg.throwIfAbandoned(data).runA(MockState .empty).attempt.map(_.leftMap(_.getMessage))
89
+ assertIO(obtained, Left (" Skipping because last commit is older than 1d" ))
90
+ }
58
91
}
0 commit comments