Skip to content

Commit

Permalink
add (failing) test for integration between LocalLibraryProvider and L…
Browse files Browse the repository at this point in the history
…ocalLibraryManager (creating vs finding created libraries)
  • Loading branch information
radeusgd committed Aug 28, 2023
1 parent cfdaab1 commit be9df1d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class LocalLibraryManager(
val libraryPath =
LocalLibraryProvider.resolveLibraryPath(librariesRoot, libraryName)
if (Files.exists(libraryPath)) {
// TODO [RW] we could try finding alternative names (as directory name does not matter for local libraries), to find a free name
throw new RuntimeException("Local library already exists")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.enso.languageserver.libraries

import akka.actor.ActorSystem
import akka.testkit._
import org.enso.distribution.FileSystem.PathSyntax
import org.enso.editions.LibraryName
import org.enso.librarymanager.LibraryLocations
import org.enso.pkg.PackageManager
import org.enso.testkit.WithTemporaryDirectory
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.BeforeAndAfterAll
import org.scalatest.time.SpanSugar.convertIntToGrainOfTime

import scala.concurrent.duration.FiniteDuration

class LocalLibraryManagerSpec
extends TestKit(ActorSystem("TestSystem"))
with ImplicitSender
with AnyWordSpecLike
with Matchers
with BeforeAndAfterAll
with WithTemporaryDirectory {

val Timeout: FiniteDuration = 10.seconds

override def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}

"LocalLibraryManager" should {
"find the libraries it has itself created" in {
val projectRoot = getTestDirectory / "project-root"
PackageManager.Default.create(projectRoot.toFile, "Test_Project_123")
val localLibraryRoot = getTestDirectory / "local-library-root"
val libraryLocations = LibraryLocations(
List(localLibraryRoot),
getTestDirectory / "library-cache-root",
List()
)
val manager =
system.actorOf(
LocalLibraryManager.props(projectRoot.toFile, libraryLocations)
)

val myLibraryName = LibraryName("user456", "My_Library")

manager ! LocalLibraryManagerProtocol.Create(
myLibraryName,
Seq(),
Seq(),
"CC0"
)
expectMsg(Timeout, LocalLibraryManagerProtocol.EmptyResponse())

manager ! LocalLibraryManagerProtocol.FindLibrary(myLibraryName)
expectMsgPF(Timeout, "FindLibraryResponse") {
case LocalLibraryManagerProtocol.FindLibraryResponse(Some(root)) =>
assert(root.location.startsWith(localLibraryRoot))
}

manager ! LocalLibraryManagerProtocol.ListLocalLibraries
val foundLibraries = expectMsgPF(Timeout, "ListLocalLibrariesResponse") {
case LocalLibraryManagerProtocol.ListLocalLibrariesResponse(
libraries
) =>
libraries
}
foundLibraries.map(entry =>
LibraryName(entry.namespace, entry.name)
) should contain theSameElementsAs Seq(myLibraryName)
}
}
}

0 comments on commit be9df1d

Please sign in to comment.