Skip to content

Commit

Permalink
test: wip analyzer test + added idea of possible tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tassiluca committed Feb 21, 2024
1 parent 3e5a0e1 commit 13d2825
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
package io.github.tassiLuca.analyzer.core

import gears.async.default.given
import gears.async.Async
import io.github.tassiLuca.analyzer.lib.Analyzer
import io.github.tassiLuca.analyzer.commons.lib.{Contribution, Release, Repository, RepositoryReport}
import io.github.tassiLuca.analyzer.lib.{Analyzer, GitHubService}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class AnalyzerTest extends AnyFlatSpec with Matchers {

private val analyzer = Analyzer.ofGitHub
val mockGitHubService: GitHubService = new GitHubService:
override def repositoriesOf(organizationName: String)(using Async): Either[String, Seq[Repository]] =
Right(Seq(Repository(0, "dse/test-1", 100, 10), Repository(1, "dse/test-2", 123, 198)))

override def contributorsOf(
organizationName: String,
repositoryName: String,
)(using Async): Either[String, Seq[Contribution]] = repositoryName match
case "test-1" => Right(Seq(Contribution("mrossi", 56), Contribution("lpluto", 11)))
case "test-2" => Right(Seq(Contribution("mrossi", 11), Contribution("averdi", 98)))

override def lastReleaseOf(organizationName: String, repositoryName: String)(using Async): Either[String, Release] =
repositoryName match
case "test-1" => Right(Release("v0.1", "2024-02-21"))
case _ => Left("404, not found")

val analyzer: Analyzer = Analyzer.of(mockGitHubService)

val expectedResults = Seq(
RepositoryReport(
"test-1",
10,
100,
Seq(Contribution("mrossi", 56), Contribution("lpluto", 11)),
Some(Release("v0.1", "2024-02-21")),
),
RepositoryReport(
"test-2",
198,
123,
Seq(Contribution("mrossi", 11), Contribution("averdi", 98)),
None,
),
)

"simple test" should "work" in {
var results: Set[RepositoryReport] = Set()
Async.blocking:
val allResults = analyzer.analyze("dse") { report =>
results += report
}
println(allResults)
allResults.isRight shouldBe true
allResults.map(_ should contain theSameElementsAs expectedResults)
results.toSeq should contain theSameElementsAs expectedResults
}
}
59 changes: 59 additions & 0 deletions commons/src/test/scala/io/github/tassiLuca/TasksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,62 @@ class TasksTest extends AnyFunSpec with Matchers {
}
}
}

//// "Weird" behaviour
// "test" should "work" in {
// Async.blocking:
// @volatile var end = false
// val timer = Timer(2 seconds)
// Future {
// timer.run()
// }
// val f = Future:
// val tf = Future {
// timer.src.awaitResult; end = true
// }
// val tr = Task {
// if end then Failure(Error()) else println("hello")
// }.schedule(RepeatUntilFailure()).run
// tf.altWithCancel(tr).awaitResult
// println(f.awaitResult)
// }
//
// "test" should "not work" in {
// Async.blocking:
// val timer = Timer(2 seconds)
// Future {
// timer.run()
// }
// val f = Future:
// val tf = Future {
// timer.src.awaitResult
// }
// val tr = Task {
// println("hello")
// }.schedule(RepeatUntilFailure).run // non c'è chiamata bloccante, se ci fosse andrebbe bene
// tf.altWithCancel(tr).awaitResult
// tr.cancel()
// println(f.awaitResult)
// }

// object TestCancellation3:
//
// class Producer3(using Async):
// val channel = UnboundedChannel[Int]()
//
// def run(): Future[Unit] = Task {
// channel.send(Random.nextInt())
// }.schedule(Every(1_000)).run
//
// def cancel(): Unit = Async.current.group.cancel()
//
// @main def testCancellation(): Unit =
// Async.blocking:
// val p = Producer3()
// val f1 = p.run()
// val f2 = Task {
// println(s"${p.channel.read()}!")
// }.schedule(Every(1_000)).run
// Thread.sleep(10_000)
// p.cancel()
// p.run().awaitResult

0 comments on commit 13d2825

Please sign in to comment.