mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-25 04:27:41 +08:00
fix morny test package path problem, add test for hash file and NamingUtils
This commit is contained in:
parent
e7f403202d
commit
a32018d600
10
build.gradle
10
build.gradle
@ -23,7 +23,8 @@ if (!proj_git)
|
||||
println "[MornyBuild] git repository not available for current working space! git version tag will be disabled."
|
||||
else if (isCleanBuild()) {
|
||||
println "git: clean build at ${grgit.head().id}"
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
final Status status = grgit.status()
|
||||
println "git: non-clean-build"
|
||||
if (!status.unstaged.allChanges.empty) {
|
||||
@ -45,7 +46,8 @@ final String proj_version_base = VERSION
|
||||
final String proj_version_delta = VERSION_DELTA
|
||||
final boolean proj_version_use_delta = Boolean.parseBoolean(USE_DELTA)
|
||||
final String proj_version = proj_version_base + (proj_version_use_delta ? "-δ${proj_version_delta}" : "")
|
||||
final String proj_version_full = proj_version + (proj_git ? "+git.${proj_commit.substring(0, 8)}" + (proj_clean?"":".δ") : "")
|
||||
final String proj_version_full = proj_version + (proj_git ?
|
||||
"+git.${proj_commit.substring(0, 8)}" + (proj_clean ? "" : ".δ") : "")
|
||||
final String proj_version_codename = CODENAME
|
||||
final long proj_code_time = proj_clean ? grgit.head().dateTime.toInstant().toEpochMilli() : System.currentTimeMillis()
|
||||
|
||||
@ -80,6 +82,7 @@ dependencies {
|
||||
|
||||
implementation "cc.sukazyo:messiva:${lib_messiva_v}"
|
||||
implementation "cc.sukazyo:resource-tools:${lib_resourcetools_v}"
|
||||
testImplementation "cc.sukazyo:resource-tools:${lib_resourcetools_v}"
|
||||
|
||||
implementation "com.github.pengrad:java-telegram-bot-api:${lib_javatelegramapi_v}"
|
||||
implementation "com.squareup.okhttp3:okhttp:${lib_okhttp_v}"
|
||||
@ -88,7 +91,8 @@ dependencies {
|
||||
testImplementation "org.scalatest:scalatest_$proj_scala_api:${lib_scalatest_v}"
|
||||
testImplementation "org.scalatest:scalatest-freespec_$proj_scala_api:${lib_scalatest_v}"
|
||||
testRuntimeOnly "org.scala-lang.modules:scala-xml_$proj_scala_api:${lib_scalamodule_xml_v}"
|
||||
testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.64.6' // for generating HTML report // required by gradle-scalatest plugin
|
||||
testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.64.6'
|
||||
// for generating HTML report // required by gradle-scalatest plugin
|
||||
|
||||
}
|
||||
|
||||
|
BIN
src/test/resources/assets_morny_tests/md5.gif
Normal file
BIN
src/test/resources/assets_morny_tests/md5.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
@ -1,10 +1,14 @@
|
||||
package cc.sukazyo.cono.morny.test
|
||||
|
||||
import cc.sukazyo.restools.ResourcesPackage
|
||||
import org.scalatest.freespec.AnyFreeSpec
|
||||
import org.scalatest.matchers.should
|
||||
|
||||
abstract class MornyTests extends AnyFreeSpec with should.Matchers {
|
||||
|
||||
val assets: ResourcesPackage =
|
||||
ResourcesPackage(classOf[MornyTests], "assets_morny_tests")
|
||||
|
||||
val pending_val = "[not-implemented]"
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.bot.event
|
||||
package cc.sukazyo.cono.morny.test.bot.event
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.event.OnQuestionMarkReply
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
@ -1,42 +0,0 @@
|
||||
package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.daemon
|
||||
|
||||
import cc.sukazyo.cono.morny.daemon.MedicationTimer
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
||||
import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis
|
||||
import org.scalatest.prop.TableDrivenPropertyChecks
|
||||
|
||||
import java.time.ZoneOffset
|
||||
|
||||
class MedicationTimerTest extends MornyTests with TableDrivenPropertyChecks {
|
||||
|
||||
"on calculating next notify time :" - {
|
||||
|
||||
val examples = Table(
|
||||
("current" , "notifyAt" , "useTimezone", "nextNotifyTime"),
|
||||
(("2023-10-09T23:54:10.000","+8"), Set(1, 5, 19) , "+8" , ("2023-10-10T01:00:00.000","+8")),
|
||||
(("2022-11-13T13:14:15.000","+2"), Set(7, 19, 21) , "+2" , ("2022-11-13T19:00:00.000","+2")),
|
||||
(("2022-11-13T13:14:35.000","+8"), Set(7, 19, 21) , "+8" , ("2022-11-13T19:00:00" ,"+8")),
|
||||
(("2022-11-13T13:14:35.174","+2"), Set(7, 19, 21) , "+2" , ("2022-11-13T19:00:00" ,"+2")),
|
||||
(("1998-02-01T08:14:35.871","+8"), Set(7, 19, 21) , "+8" , ("1998-02-01T19:00:00" ,"+8")),
|
||||
(("2022-11-13T00:00:00.000","-1"), Set(7, 19, 21) , "-1" , ("2022-11-13T07:00:00" ,"-1")),
|
||||
(("2022-11-21T19:00:00.000","+0"), Set(7, 19, 21) , "+0" , ("2022-11-21T21:00:00" ,"+0")),
|
||||
(("2022-12-31T21:00:00.000","+0"), Set(7, 19, 21) , "+0" , ("2023-01-01T07:00:00" ,"+0")),
|
||||
(("2125-11-18T23:45:27.062","+0"), Set(7, 19, 21) , "+0" , ("2125-11-19T07:00:00" ,"+0"))
|
||||
)
|
||||
|
||||
forAll (examples) { (current, notifyAt, useTimezone, nextNotifyTime) =>
|
||||
val _curr = EpochMillis(current)
|
||||
val _tz = ZoneOffset of useTimezone
|
||||
val _next = EpochMillis(nextNotifyTime)
|
||||
|
||||
s"at time [$_curr], and need to be notify at hours ${notifyAt.mkString(",")} with $_tz :" - {
|
||||
s"next notify should at time [$_curr]" in {
|
||||
MedicationTimer.calcNextRoutineTimestamp(_curr, _tz, notifyAt) shouldEqual _next
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package cc.sukazyo.cono.morny.test.daemon
|
||||
|
||||
import cc.sukazyo.cono.morny.daemon.MedicationTimer
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
||||
import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis
|
||||
import org.scalatest.prop.TableDrivenPropertyChecks
|
||||
|
||||
import java.time.ZoneOffset
|
||||
|
||||
class MedicationTimerTest extends MornyTests with TableDrivenPropertyChecks {
|
||||
|
||||
"on calculating next notify time :" - {
|
||||
|
||||
val examples = Table(
|
||||
("current", "notifyAt", "useTimezone", "nextNotifyTime"),
|
||||
(("2023-10-09T23:54:10.000", "+8"), Set(1, 5, 19), "+8", ("2023-10-10T01:00:00.000", "+8")),
|
||||
(("2022-11-13T13:14:15.000", "+2"), Set(7, 19, 21), "+2", ("2022-11-13T19:00:00.000", "+2")),
|
||||
(("2022-11-13T13:14:35.000", "+8"), Set(7, 19, 21), "+8", ("2022-11-13T19:00:00", "+8")),
|
||||
(("2022-11-13T13:14:35.174", "+2"), Set(7, 19, 21), "+2", ("2022-11-13T19:00:00", "+2")),
|
||||
(("1998-02-01T08:14:35.871", "+8"), Set(7, 19, 21), "+8", ("1998-02-01T19:00:00", "+8")),
|
||||
(("2022-11-13T00:00:00.000", "-1"), Set(7, 19, 21), "-1", ("2022-11-13T07:00:00", "-1")),
|
||||
(("2022-11-21T19:00:00.000", "+0"), Set(7, 19, 21), "+0", ("2022-11-21T21:00:00", "+0")),
|
||||
(("2022-12-31T21:00:00.000", "+0"), Set(7, 19, 21), "+0", ("2023-01-01T07:00:00", "+0")),
|
||||
(("2125-11-18T23:45:27.062", "+0"), Set(7, 19, 21), "+0", ("2125-11-19T07:00:00", "+0"))
|
||||
)
|
||||
|
||||
forAll(examples) { (current, notifyAt, useTimezone, nextNotifyTime) =>
|
||||
val _curr = EpochMillis(current)
|
||||
val _tz = ZoneOffset of useTimezone
|
||||
val _next = EpochMillis(nextNotifyTime)
|
||||
|
||||
s"at time [$_curr], and need to be notify at hours ${notifyAt.mkString(",")} with $_tz :" - {
|
||||
s"next notify should at time [$_curr]" in {
|
||||
MedicationTimer.calcNextRoutineTimestamp(_curr, _tz, notifyAt) shouldEqual _next
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.data
|
||||
package cc.sukazyo.cono.morny.test.data
|
||||
|
||||
import cc.sukazyo.cono.morny.data.BilibiliForms.*
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
@ -67,13 +67,23 @@ class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks {
|
||||
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||
)
|
||||
)
|
||||
)),
|
||||
(
|
||||
"md5.gif", ExampleHashValue(
|
||||
"f5ca4f935d44b85c431a8bf788c0eaca",
|
||||
"784cefac7a3699d704756d1a04189d6157405906",
|
||||
"c0aa75d5345efae1019ca7a56eabc8673499dcee8ab8a8d657fb69f1f929b909",
|
||||
"2d3123c543aa1745eeae57d2e6c31b6ea07dd2bb14cef2b5939116f9cf705953fb43cf6162c87ee1c7175d1de4af6d9de6f2bc817065cc854b912877848f937b"
|
||||
))
|
||||
)
|
||||
|
||||
forAll(examples_binary) { (file, hashes) =>
|
||||
val _name = if file == null then "empty file" else s"file $file"
|
||||
val _data = if file == null then Array.empty[Byte] else throw NotImplementedError("does not applied file get yet")
|
||||
val _data =
|
||||
if file == null then
|
||||
Array.empty[Byte]
|
||||
else
|
||||
assets.getResource(file).read.readAllBytes
|
||||
|
||||
s"while hashing binary $_name :" - {
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package cc.sukazyo.cono.morny.test.utils
|
||||
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
||||
|
||||
class FileUtilsTest extends MornyTests {
|
||||
|
||||
"while getting the MD5 hash of a file :" in pending
|
||||
|
||||
}
|
@ -1,24 +1,39 @@
|
||||
package cc.sukazyo.cono.morny.test.utils.tgapi.formatting
|
||||
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
||||
import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils
|
||||
|
||||
class NamingUtilsTest extends MornyTests {
|
||||
|
||||
"while generating inline query result id :" - {
|
||||
|
||||
import NamingUtils.inlineQueryId
|
||||
|
||||
"while not use no data :" - {
|
||||
|
||||
"(different tag) should return different id" in pending
|
||||
"(same tag) should return the same id" in pending
|
||||
"(different tag) should return different id" in:
|
||||
inlineQueryId("abc") should not equal inlineQueryId("abd")
|
||||
inlineQueryId("abc") should not equal inlineQueryId("abe")
|
||||
"(same tag) should return the same id" in:
|
||||
inlineQueryId("abc") shouldEqual inlineQueryId("abc")
|
||||
inlineQueryId("[e]vo]wvr'L\"pno[irvP)v]") shouldEqual inlineQueryId("[e]vo]wvr'L\"pno[irvP)v]")
|
||||
|
||||
}
|
||||
|
||||
"while use data :" - {
|
||||
|
||||
"(same tag) with (same data) should return the same id" in pending
|
||||
"(same tag) with (different data) should return different id" in pending
|
||||
"(different tag) with (same data) should return different id" in pending
|
||||
"change tag and data position should return different id" in pending
|
||||
"(same tag) with (same data) should return the same id" in:
|
||||
inlineQueryId("random-tag", "123456789") shouldEqual
|
||||
inlineQueryId("random-tag", "123456789")
|
||||
"(same tag) with (different data) should return different id" in:
|
||||
inlineQueryId("random-tag", "123456789") should not equal
|
||||
inlineQueryId("random-tag", "987654321")
|
||||
"(different tag) with (same data) should return different id" in:
|
||||
inlineQueryId("random-tag", "123456789") should not equal
|
||||
inlineQueryId("set-tag", "123456789")
|
||||
"change tag and data position should return different id" in:
|
||||
inlineQueryId("tag", "data") should not equal
|
||||
inlineQueryId("data", "tag")
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ class TelegramUserInformationTest extends MornyTests with TableDrivenPropertyChe
|
||||
private val examples_telegram_cdn = Table(
|
||||
("username", "cdn"),
|
||||
("Eyre_S", "cdn5"),
|
||||
("ankarinnie", "cdn1")
|
||||
)
|
||||
|
||||
forAll(examples_telegram_cdn) ((username, cdn) => s"while user is @$username :" - {
|
||||
|
Loading…
Reference in New Issue
Block a user