Repository: scala-steward-org/scala-steward
Pull request #2324 (2021-11-01 07:39:57)

Test RefreshErrorAlg

codecov[bot]: # [Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) Report
> Merging [#2324](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) (83d688e) into [master](https://codecov.io/gh/scala-steward-org/scala-steward/commit/6c935a5ede4b3777704b501e6965beafdaf8aa9e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) (6c935a5) will **increase** coverage by `0.33%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324/graphs/tree.svg?width=650&height=150&src=pr&token=udzMsc1Dne&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)

```diff
@@            Coverage Diff             @@
##           master    #2324      +/-   ##
==========================================
+ Coverage   78.45%   78.79%   +0.33%     
==========================================
  Files         136      135       -1     
  Lines        2349     2348       -1     
  Branches       58       58              
==========================================
+ Hits         1843     1850       +7     
+ Misses        506      498       -8     
```


| [Impacted Files](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org) | Coverage Δ | |
|---|---|---|
| [...la/org/scalasteward/core/application/Context.scala](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org#diff-bW9kdWxlcy9jb3JlL3NyYy9tYWluL3NjYWxhL29yZy9zY2FsYXN0ZXdhcmQvY29yZS9hcHBsaWNhdGlvbi9Db250ZXh0LnNjYWxh) | `77.58% <ø> (ø)` | |
| [...la-2.12/org/scalasteward/mill/plugin/package.scala](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org#diff-bW9kdWxlcy9taWxsLXBsdWdpbi9zcmMvbWFpbi9zY2FsYS0yLjEyL29yZy9zY2FsYXN0ZXdhcmQvbWlsbC9wbHVnaW4vcGFja2FnZS5zY2FsYQ==) | | |
| [.../scalasteward/core/repocache/RefreshErrorAlg.scala](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org#diff-bW9kdWxlcy9jb3JlL3NyYy9tYWluL3NjYWxhL29yZy9zY2FsYXN0ZXdhcmQvY29yZS9yZXBvY2FjaGUvUmVmcmVzaEVycm9yQWxnLnNjYWxh) | `53.33% <0.00%> (+46.66%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org). Last update [6c935a5...83d688e](https://codecov.io/gh/scala-steward-org/scala-steward/pull/2324?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scala-steward-org).


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
index 8caebb80..612e8700 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
@@ -61,6 +61,7 @@ final class Context[F[_]](implicit
     val millAlg: MillAlg[F],
     val pruningAlg: PruningAlg[F],
     val pullRequestRepository: PullRequestRepository[F],
+    val refreshErrorAlg: RefreshErrorAlg[F],
     val repoConfigAlg: RepoConfigAlg[F],
     val sbtAlg: SbtAlg[F],
     val artifactMigrationsLoader: ArtifactMigrationsLoader[F],
diff --git a/modules/core/src/main/scala/org/scalasteward/core/repocache/RefreshErrorAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/repocache/RefreshErrorAlg.scala
index 8f121812..67ffdf23 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/repocache/RefreshErrorAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/repocache/RefreshErrorAlg.scala
@@ -46,7 +46,7 @@ final class RefreshErrorAlg[F[_]](
   def persistError[A](repo: Repo)(fa: F[A]): F[A] =
     fa.handleErrorWith { t =>
       dateTimeAlg.currentTimestamp.flatMap { now =>
-        kvStore.put(repo, Entry(now, t.getMessage))
+        kvStore.put(repo, Entry(now, t.toString))
       } >> F.raiseError[A](t)
     }
 


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/mock/MockConfig.scala b/modules/core/src/test/scala/org/scalasteward/core/mock/MockConfig.scala
index 1d116bfb..ba768f79 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/mock/MockConfig.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/mock/MockConfig.scala
@@ -22,7 +22,8 @@ object MockConfig {
     gitAskPass = mockRoot / "askpass.sh",
     enableSandbox = Some(true),
     envVar = List(EnvVar("VAR1", "val1"), EnvVar("VAR2", "val2")),
-    cacheTtl = 1.hour
+    cacheTtl = 1.hour,
+    refreshBackoffPeriod = 1.hour
   )
   val config: Config = Config.from(args)
   val envVars = List(s"GIT_ASKPASS=${config.gitCfg.gitAskPass}", "VAR1=val1", "VAR2=val2")
diff --git a/modules/core/src/test/scala/org/scalasteward/core/repocache/RefreshErrorAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/repocache/RefreshErrorAlgTest.scala
new file mode 100644
index 00000000..8156e8e7
--- /dev/null
+++ b/modules/core/src/test/scala/org/scalasteward/core/repocache/RefreshErrorAlgTest.scala
@@ -0,0 +1,29 @@
+package org.scalasteward.core.repocache
+
+import cats.syntax.all._
+import munit.CatsEffectSuite
+import org.scalasteward.core.mock.MockContext.context.refreshErrorAlg
+import org.scalasteward.core.mock.{MockEff, MockState}
+import org.scalasteward.core.vcs.data.Repo
+
+class RefreshErrorAlgTest extends CatsEffectSuite {
+  test("skipIfFailedRecently: not failed") {
+    val repo = Repo("refresh-error", "test-1")
+    val expected = 42
+    refreshErrorAlg.skipIfFailedRecently(repo)(MockEff.pure(expected)).runA(MockState.empty).map {
+      obtained => assertEquals(obtained, expected)
+    }
+  }
+
+  test("skipIfFailedRecently: failed") {
+    val repo = Repo("refresh-error", "test-2")
+    val p = refreshErrorAlg.persistError(repo)(MockEff.raiseError(new Throwable())).attempt >>
+      refreshErrorAlg.skipIfFailedRecently(repo)(MockEff.unit)
+
+    val expected = "Skipping due to previous error"
+    p.runA(MockState.empty).attempt.map { obtained =>
+      val message = obtained.fold(_.getMessage, _.toString).take(expected.length)
+      assertEquals(message, expected)
+    }
+  }
+}