Skip Google search tests with CI to preserve daily rate limit
This commit is contained in:
parent
40ee593c3b
commit
7581c26d59
8 changed files with 79 additions and 46 deletions
42
build.gradle
42
build.gradle
|
@ -19,16 +19,16 @@ final def deployDir = 'deploy'
|
||||||
final def semverProcessor = "net.thauvin.erik:semver:1.2.0"
|
final def semverProcessor = "net.thauvin.erik:semver:1.2.0"
|
||||||
|
|
||||||
def isNonStable = { String version ->
|
def isNonStable = { String version ->
|
||||||
def stableKeyword = ['RELEASE', 'FINAL', 'GA', 'JRE'].any { it -> version.toUpperCase().contains(it) }
|
def stableKeyword = ['RELEASE', 'FINAL', 'GA', 'JRE'].any { it -> version.toUpperCase().contains(it) }
|
||||||
def regex = /^[0-9,.v-]+(-r)?$/
|
def regex = /^[0-9,.v-]+(-r)?$/
|
||||||
return !stableKeyword && !(version ==~ regex)
|
return !stableKeyword && !(version ==~ regex)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainClassName = packageName + '.Mobibot'
|
mainClassName = packageName + '.Mobibot'
|
||||||
|
|
||||||
ext.versions = [
|
ext.versions = [
|
||||||
log4j: '2.18.0',
|
log4j: '2.18.0',
|
||||||
pmd : '6.49.0',
|
pmd : '6.49.0',
|
||||||
]
|
]
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -46,12 +46,12 @@ dependencies {
|
||||||
//implementation 'com.github.pircbotx:pircbotx:-SNAPSHOT'
|
//implementation 'com.github.pircbotx:pircbotx:-SNAPSHOT'
|
||||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||||
|
|
||||||
// Commons
|
// Commons (mostly for PircBotX)
|
||||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||||
implementation 'org.apache.commons:commons-text:1.9'
|
implementation 'org.apache.commons:commons-text:1.9'
|
||||||
implementation 'commons-codec:commons-codec:1.15'
|
implementation 'commons-codec:commons-codec:1.15'
|
||||||
implementation 'commons-net:commons-net:3.8.0'
|
implementation 'commons-net:commons-net:3.8.0'
|
||||||
|
|
||||||
// Google
|
// Google
|
||||||
implementation 'com.google.code.gson:gson:2.9.1'
|
implementation 'com.google.code.gson:gson:2.9.1'
|
||||||
implementation 'com.google.guava:guava:31.1-jre'
|
implementation 'com.google.guava:guava:31.1-jre'
|
||||||
|
@ -60,7 +60,7 @@ dependencies {
|
||||||
implementation platform('org.jetbrains.kotlin:kotlin-bom')
|
implementation platform('org.jetbrains.kotlin:kotlin-bom')
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
|
||||||
implementation'org.jetbrains.kotlinx:kotlinx-cli:0.3.5'
|
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.5'
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
implementation 'org.slf4j:slf4j-api:2.0.1'
|
implementation 'org.slf4j:slf4j-api:2.0.1'
|
||||||
|
@ -87,12 +87,21 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
useTestNG() {
|
||||||
|
suites('src/test/resources/testng-ci.xml')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(Test).configureEach {
|
||||||
testLogging {
|
testLogging {
|
||||||
exceptionFormat = 'full'
|
exceptionFormat = 'full'
|
||||||
events('skipped', 'failed')
|
events('skipped', 'failed')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task testAll(type: Test, group: 'verification', description: 'Run all tests.') {
|
||||||
useTestNG() {
|
useTestNG() {
|
||||||
options.suites('src/test/resources/testng.xml')
|
suites('src/test/resources/testng.xml')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +121,18 @@ tasks.withType(JavaCompile) {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = 'UTF-8'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
|
||||||
dependsOn 'incrementBuildMeta'
|
|
||||||
options.compilerArgs += ['-Xlint:unchecked', '-Xlint:deprecation']
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = java.targetCompatibility.toString()
|
jvmTarget = java.targetCompatibility.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileJava {
|
||||||
|
dependsOn 'incrementBuildMeta'
|
||||||
|
options.compilerArgs += ['-Xlint:unchecked', '-Xlint:deprecation']
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tasks.named("dependencyUpdates").configure {
|
tasks.named("dependencyUpdates").configure {
|
||||||
rejectVersionIf {
|
rejectVersionIf {
|
||||||
isNonStable(it.candidate.version)
|
isNonStable(it.candidate.version)
|
||||||
|
@ -164,7 +174,7 @@ incrementBuildMeta {
|
||||||
if (!System.getenv('CI')) {
|
if (!System.getenv('CI')) {
|
||||||
buildMeta = sprintf("%03d", (buildMeta as Integer) + 1)
|
buildMeta = sprintf("%03d", (buildMeta as Integer) + 1)
|
||||||
} else {
|
} else {
|
||||||
println 'No increment on CIs.'
|
println 'No increment with CI.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,5 +219,5 @@ task deploy {
|
||||||
task release {
|
task release {
|
||||||
group = 'Publishing'
|
group = 'Publishing'
|
||||||
description = 'Releases new version.'
|
description = 'Releases new version.'
|
||||||
dependsOn(wrapper, 'deploy')
|
dependsOn(wrapper, deploy)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List<String?>)</ID>
|
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List<String?>)</ID>
|
||||||
<ID>NestedBlockDepth:FeedsMgr.kt$FeedsMgr.Companion$@JvmStatic @Throws(IOException::class, FeedException::class) fun loadFeed(entries: Entries, currentFile: String = currentXml): String</ID>
|
<ID>NestedBlockDepth:FeedsMgr.kt$FeedsMgr.Companion$@JvmStatic @Throws(IOException::class, FeedException::class) fun loadFeed(entries: Entries, currentFile: String = currentXml): String</ID>
|
||||||
<ID>NestedBlockDepth:FeedsMgr.kt$FeedsMgr.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = currentXml)</ID>
|
<ID>NestedBlockDepth:FeedsMgr.kt$FeedsMgr.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = currentXml)</ID>
|
||||||
<ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message></ID>
|
<ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List<Message></ID>
|
||||||
<ID>NestedBlockDepth:LinksMgr.kt$LinksMgr$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
|
<ID>NestedBlockDepth:LinksMgr.kt$LinksMgr$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
|
||||||
<ID>NestedBlockDepth:Lookup.kt$Lookup$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID>
|
<ID>NestedBlockDepth:Lookup.kt$Lookup$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID>
|
||||||
<ID>NestedBlockDepth:Posting.kt$Posting$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
|
<ID>NestedBlockDepth:Posting.kt$Posting$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
<ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID>
|
<ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID>
|
||||||
<ID>SwallowedException:WolframAlpha.kt$WolframAlpha.Companion$ioe: IOException</ID>
|
<ID>SwallowedException:WolframAlpha.kt$WolframAlpha.Companion$ioe: IOException</ID>
|
||||||
<ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID>
|
<ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID>
|
||||||
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message></ID>
|
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List<Message></ID>
|
||||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message></ID>
|
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message></ID>
|
||||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>
|
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>
|
||||||
<ID>ThrowsCount:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message></ID>
|
<ID>ThrowsCount:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message></ID>
|
||||||
|
|
|
@ -34,10 +34,11 @@ package net.thauvin.erik.mobibot.commands.seen
|
||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
class NickComparator: Comparator<String>, Serializable {
|
class NickComparator : Comparator<String>, Serializable {
|
||||||
override fun compare(a: String, b: String): Int {
|
override fun compare(a: String, b: String): Int {
|
||||||
return a.lowercase().compareTo(b.lowercase())
|
return a.lowercase().compareTo(b.lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val serialVersionUID = 1L
|
private const val serialVersionUID = 1L
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
package net.thauvin.erik.mobibot.modules
|
package net.thauvin.erik.mobibot.modules
|
||||||
|
|
||||||
|
import net.thauvin.erik.mobibot.ReleaseInfo
|
||||||
import net.thauvin.erik.mobibot.Utils.capitalise
|
import net.thauvin.erik.mobibot.Utils.capitalise
|
||||||
import net.thauvin.erik.mobibot.Utils.encodeUrl
|
import net.thauvin.erik.mobibot.Utils.encodeUrl
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||||
|
@ -64,8 +65,10 @@ class GoogleSearch : ThreadedModule() {
|
||||||
if (args.isNotBlank()) {
|
if (args.isNotBlank()) {
|
||||||
try {
|
try {
|
||||||
val results = searchGoogle(
|
val results = searchGoogle(
|
||||||
args, properties[GOOGLE_API_KEY_PROP],
|
args,
|
||||||
properties[GOOGLE_CSE_KEY_PROP]
|
properties[GOOGLE_API_KEY_PROP],
|
||||||
|
properties[GOOGLE_CSE_KEY_PROP],
|
||||||
|
event.user.nick
|
||||||
)
|
)
|
||||||
for (msg in results) {
|
for (msg in results) {
|
||||||
event.sendMessage(channel, msg)
|
event.sendMessage(channel, msg)
|
||||||
|
@ -96,7 +99,12 @@ class GoogleSearch : ThreadedModule() {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Throws(ModuleException::class)
|
@Throws(ModuleException::class)
|
||||||
fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message> {
|
fun searchGoogle(
|
||||||
|
query: String,
|
||||||
|
apiKey: String?,
|
||||||
|
cseKey: String?,
|
||||||
|
quotaUser: String = ReleaseInfo.PROJECT
|
||||||
|
): List<Message> {
|
||||||
if (apiKey.isNullOrBlank() || cseKey.isNullOrBlank()) {
|
if (apiKey.isNullOrBlank() || cseKey.isNullOrBlank()) {
|
||||||
throw ModuleException(
|
throw ModuleException(
|
||||||
"${GoogleSearch::class.java.name} is disabled.",
|
"${GoogleSearch::class.java.name} is disabled.",
|
||||||
|
@ -108,7 +116,7 @@ class GoogleSearch : ThreadedModule() {
|
||||||
try {
|
try {
|
||||||
val url = URL(
|
val url = URL(
|
||||||
"https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cseKey" +
|
"https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cseKey" +
|
||||||
"&q=${query.encodeUrl()}&filter=1&num=5&alt=json"
|
""aUser=${quotaUser}&q=${query.encodeUrl()}&filter=1&num=5&alt=json"
|
||||||
)
|
)
|
||||||
val json = JSONObject(url.reader())
|
val json = JSONObject(url.reader())
|
||||||
if (json.has("items")) {
|
if (json.has("items")) {
|
||||||
|
|
|
@ -52,35 +52,35 @@ import org.testng.annotations.Test
|
||||||
*/
|
*/
|
||||||
class GoogleSearchTest : LocalProperties() {
|
class GoogleSearchTest : LocalProperties() {
|
||||||
@Test
|
@Test
|
||||||
|
fun testAPIKeys() {
|
||||||
|
assertThat(
|
||||||
|
searchGoogle("", "apikey", "cssKey").first(),
|
||||||
|
"empty query"
|
||||||
|
).isInstanceOf(ErrorMessage::class.java)
|
||||||
|
|
||||||
|
assertThat { searchGoogle("test", "", "apiKey") }.isFailure()
|
||||||
|
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||||
|
|
||||||
|
assertThat { searchGoogle("test", "apiKey", "") }.isFailure()
|
||||||
|
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = ["no-ci"])
|
||||||
@Throws(ModuleException::class)
|
@Throws(ModuleException::class)
|
||||||
fun testSearchGoogle() {
|
fun testSearchGoogle() {
|
||||||
val apiKey = getProperty(GoogleSearch.GOOGLE_API_KEY_PROP)
|
val apiKey = getProperty(GoogleSearch.GOOGLE_API_KEY_PROP)
|
||||||
val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
|
val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
|
||||||
try {
|
|
||||||
var messages = searchGoogle("mobitopia", apiKey, cseKey)
|
|
||||||
assertThat(messages, "mobitopia results not empty").isNotEmpty()
|
|
||||||
assertThat(messages[0].msg, "found mobibtopia").contains("mobitopia", true)
|
|
||||||
|
|
||||||
messages = searchGoogle("aapl", apiKey, cseKey)
|
try {
|
||||||
assertThat(messages, "aapl results not empty").isNotEmpty()
|
var messages = searchGoogle("mobibot", apiKey, cseKey)
|
||||||
assertThat(messages[0].msg, "found apple").contains("apple", true)
|
assertThat(messages, "mobibot results not empty").isNotEmpty()
|
||||||
|
assertThat(messages[0].msg, "found mobibot").contains("mobibot", true)
|
||||||
|
|
||||||
messages = searchGoogle("adadflkjl", apiKey, cseKey)
|
messages = searchGoogle("adadflkjl", apiKey, cseKey)
|
||||||
assertThat(messages[0], "not found").all {
|
assertThat(messages[0], "not found").all {
|
||||||
isInstanceOf(ErrorMessage::class.java)
|
isInstanceOf(ErrorMessage::class.java)
|
||||||
prop(Message::msg).isEqualTo("No results found.")
|
prop(Message::msg).isEqualTo("No results found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(
|
|
||||||
searchGoogle("", "apikey", "cssKey").first(),
|
|
||||||
"empty query"
|
|
||||||
).isInstanceOf(ErrorMessage::class.java)
|
|
||||||
|
|
||||||
assertThat { searchGoogle("test", "", "apiKey") }.isFailure()
|
|
||||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
|
||||||
|
|
||||||
assertThat { searchGoogle("test", "apiKey", "") }.isFailure()
|
|
||||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
// Avoid displaying api keys in CI logs
|
// Avoid displaying api keys in CI logs
|
||||||
if ("true" == System.getenv("CI")) {
|
if ("true" == System.getenv("CI")) {
|
||||||
|
|
14
src/test/resources/testng-ci.xml
Normal file
14
src/test/resources/testng-ci.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
||||||
|
<suite name="testng-ci">
|
||||||
|
<test name="ci">
|
||||||
|
<groups>
|
||||||
|
<run>
|
||||||
|
<exclude name="no-ci"/>
|
||||||
|
</run>
|
||||||
|
</groups>
|
||||||
|
<packages>
|
||||||
|
<package name="net.thauvin.erik.mobibot.*"/>
|
||||||
|
</packages>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="tests">
|
<suite name="testng">
|
||||||
<test name="full">
|
<test name="all">
|
||||||
<packages>
|
<packages>
|
||||||
<package name="net.thauvin.erik.mobibot.*"/>
|
<package name="net.thauvin.erik.mobibot.*"/>
|
||||||
</packages>
|
</packages>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Fri Sep 16 14:23:24 PDT 2022
|
#Fri Sep 16 21:07:43 PDT 2022
|
||||||
version.buildmeta=544
|
version.buildmeta=574
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=rc
|
version.prerelease=rc
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-rc+544
|
version.semver=0.8.0-rc+574
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue