mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 10:59:33 +00:00
Merge pull request #1576 from eikek/fix/addon-zip
Fix detecting addons from zip file
This commit is contained in:
commit
4b2752535c
@ -34,7 +34,7 @@ case class AddonMeta(
|
||||
s"${meta.name}-${meta.version}"
|
||||
|
||||
def parseResult: Boolean =
|
||||
options.exists(_.collectOutput)
|
||||
options.forall(_.collectOutput)
|
||||
|
||||
def ignoreResult: Boolean =
|
||||
!parseResult
|
||||
@ -200,7 +200,7 @@ object AddonMeta {
|
||||
)
|
||||
)
|
||||
zipFile
|
||||
.through(Zip.unzip(8192, Glob("**/docspell-addon.*")))
|
||||
.through(Zip.unzip(8192, Glob("docspell-addon.*|**/docspell-addon.*")))
|
||||
.filter(bin => !bin.name.endsWith("/"))
|
||||
.flatMap { bin =>
|
||||
if (bin.extensionIn(Set("json"))) Stream.eval(AddonMeta.fromJsonBytes(bin.data))
|
||||
|
BIN
modules/addonlib/src/test/resources/minimal-addon.zip
Normal file
BIN
modules/addonlib/src/test/resources/minimal-addon.zip
Normal file
Binary file not shown.
@ -31,6 +31,54 @@ class AddonArchiveTest extends CatsEffectSuite with TestLoggingConfig with Fixtu
|
||||
} yield ()
|
||||
}
|
||||
|
||||
test("Read archive from zip") {
|
||||
for {
|
||||
aa <- AddonArchive.read[IO](dummyAddonUrl, UrlReader.defaultReader[IO], None)
|
||||
_ = {
|
||||
assertEquals(aa.name, "dummy-addon")
|
||||
assertEquals(aa.version, "2.9")
|
||||
assertEquals(aa.url, dummyAddonUrl)
|
||||
}
|
||||
} yield ()
|
||||
}
|
||||
|
||||
tempDir.test("Read generated addon from path") { dir =>
|
||||
AddonGenerator.successAddon("mini-addon").use { addon =>
|
||||
for {
|
||||
archive <- IO(AddonArchive(addon.url, "", ""))
|
||||
path <- archive.extractTo[IO](UrlReader.defaultReader[IO], dir)
|
||||
|
||||
read <- AddonArchive.read[IO](addon.url, UrlReader.defaultReader[IO], path.some)
|
||||
_ = assertEquals(addon, read)
|
||||
} yield ()
|
||||
}
|
||||
}
|
||||
|
||||
test("Read generated addon from zip") {
|
||||
AddonGenerator.successAddon("mini-addon").use { addon =>
|
||||
for {
|
||||
read <- AddonArchive.read[IO](addon.url, UrlReader.defaultReader[IO], None)
|
||||
_ = assertEquals(addon, read)
|
||||
} yield ()
|
||||
}
|
||||
}
|
||||
|
||||
tempDir.test("Read minimal addon from path") { dir =>
|
||||
for {
|
||||
archive <- IO(AddonArchive(miniAddonUrl, "", ""))
|
||||
path <- archive.extractTo(UrlReader.defaultReader[IO], dir)
|
||||
aa <- AddonArchive.read(miniAddonUrl, UrlReader.defaultReader[IO], path.some)
|
||||
_ = assertEquals(aa, AddonArchive(miniAddonUrl, "minimal-addon", "0.1.0"))
|
||||
} yield ()
|
||||
}
|
||||
|
||||
test("Read minimal addon from zip") {
|
||||
for {
|
||||
aa <- AddonArchive.read(miniAddonUrl, UrlReader.defaultReader[IO], None)
|
||||
_ = assertEquals(aa, AddonArchive(miniAddonUrl, "minimal-addon", "0.1.0"))
|
||||
} yield ()
|
||||
}
|
||||
|
||||
test("Read archive from zip file") {
|
||||
for {
|
||||
archive <- AddonArchive.read[IO](dummyAddonUrl, UrlReader.defaultReader[IO])
|
||||
|
@ -28,6 +28,9 @@ trait Fixtures extends TestLoggingConfig { self: CatsEffectSuite =>
|
||||
val dummyAddonUrl =
|
||||
LenientUri.fromJava(getClass.getResource("/docspell-dummy-addon-master.zip"))
|
||||
|
||||
val miniAddonUrl =
|
||||
LenientUri.fromJava(getClass.getResource("/minimal-addon.zip"))
|
||||
|
||||
val dummyAddonMeta =
|
||||
AddonMeta(
|
||||
meta =
|
||||
|
@ -72,7 +72,7 @@ final class AddonValidate[F[_]: Async](
|
||||
).cast
|
||||
)
|
||||
_ <- EitherT.cond(
|
||||
meta.options.exists(_.isUseful),
|
||||
meta.options.forall(_.isUseful),
|
||||
(),
|
||||
InvalidAddon(
|
||||
"Addon defines no output and no networking. It can't do anything useful."
|
||||
|
@ -265,7 +265,7 @@ options:
|
||||
# docspell itself to apply any changes and the addon can run
|
||||
# completely isolated.
|
||||
#
|
||||
# Default is false.
|
||||
# Default is true.
|
||||
collectOutput: true
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user