Skip Google search tests with CI to preserve daily rate limit

This commit is contained in:
Erik C. Thauvin 2022-09-16 21:11:02 -07:00
parent 40ee593c3b
commit 7581c26d59
8 changed files with 79 additions and 46 deletions

View file

@ -19,16 +19,16 @@ final def deployDir = 'deploy'
final def semverProcessor = "net.thauvin.erik:semver:1.2.0"
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA', 'JRE'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
def stableKeyword = ['RELEASE', 'FINAL', 'GA', 'JRE'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
mainClassName = packageName + '.Mobibot'
ext.versions = [
log4j: '2.18.0',
pmd : '6.49.0',
log4j: '2.18.0',
pmd : '6.49.0',
]
repositories {
@ -46,7 +46,7 @@ dependencies {
//implementation 'com.github.pircbotx:pircbotx:-SNAPSHOT'
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-text:1.9'
implementation 'commons-codec:commons-codec:1.15'
@ -60,7 +60,7 @@ dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
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
implementation 'org.slf4j:slf4j-api:2.0.1'
@ -87,12 +87,21 @@ dependencies {
}
test {
useTestNG() {
suites('src/test/resources/testng-ci.xml')
}
}
tasks.withType(Test).configureEach {
testLogging {
exceptionFormat = 'full'
events('skipped', 'failed')
}
}
task testAll(type: Test, group: 'verification', description: 'Run all tests.') {
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'
}
compileJava {
dependsOn 'incrementBuildMeta'
options.compilerArgs += ['-Xlint:unchecked', '-Xlint:deprecation']
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = java.targetCompatibility.toString()
}
}
compileJava {
dependsOn 'incrementBuildMeta'
options.compilerArgs += ['-Xlint:unchecked', '-Xlint:deprecation']
}
tasks.named("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(it.candidate.version)
@ -164,7 +174,7 @@ incrementBuildMeta {
if (!System.getenv('CI')) {
buildMeta = sprintf("%03d", (buildMeta as Integer) + 1)
} else {
println 'No increment on CIs.'
println 'No increment with CI.'
}
}
}
@ -209,5 +219,5 @@ task deploy {
task release {
group = 'Publishing'
description = 'Releases new version.'
dependsOn(wrapper, 'deploy')
dependsOn(wrapper, deploy)
}

View file

@ -48,7 +48,7 @@
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List&lt;String?&gt;)</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:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List&lt;Message&gt;</ID>
<ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</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: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:WolframAlpha.kt$WolframAlpha.Companion$ioe: IOException</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&lt;Message&gt;</ID>
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</ID>
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</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&lt;Message&gt;</ID>

View file

@ -34,10 +34,11 @@ package net.thauvin.erik.mobibot.commands.seen
import java.io.Serializable
class NickComparator: Comparator<String>, Serializable {
class NickComparator : Comparator<String>, Serializable {
override fun compare(a: String, b: String): Int {
return a.lowercase().compareTo(b.lowercase())
}
companion object {
private const val serialVersionUID = 1L
}

View file

@ -31,6 +31,7 @@
*/
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.encodeUrl
import net.thauvin.erik.mobibot.Utils.helpFormat
@ -64,8 +65,10 @@ class GoogleSearch : ThreadedModule() {
if (args.isNotBlank()) {
try {
val results = searchGoogle(
args, properties[GOOGLE_API_KEY_PROP],
properties[GOOGLE_CSE_KEY_PROP]
args,
properties[GOOGLE_API_KEY_PROP],
properties[GOOGLE_CSE_KEY_PROP],
event.user.nick
)
for (msg in results) {
event.sendMessage(channel, msg)
@ -96,7 +99,12 @@ class GoogleSearch : ThreadedModule() {
*/
@JvmStatic
@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()) {
throw ModuleException(
"${GoogleSearch::class.java.name} is disabled.",
@ -108,7 +116,7 @@ class GoogleSearch : ThreadedModule() {
try {
val url = URL(
"https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cseKey" +
"&q=${query.encodeUrl()}&filter=1&num=5&alt=json"
"&quotaUser=${quotaUser}&q=${query.encodeUrl()}&filter=1&num=5&alt=json"
)
val json = JSONObject(url.reader())
if (json.has("items")) {

View file

@ -52,35 +52,35 @@ import org.testng.annotations.Test
*/
class GoogleSearchTest : LocalProperties() {
@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)
fun testSearchGoogle() {
val apiKey = getProperty(GoogleSearch.GOOGLE_API_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)
assertThat(messages, "aapl results not empty").isNotEmpty()
assertThat(messages[0].msg, "found apple").contains("apple", true)
try {
var messages = searchGoogle("mobibot", apiKey, cseKey)
assertThat(messages, "mobibot results not empty").isNotEmpty()
assertThat(messages[0].msg, "found mobibot").contains("mobibot", true)
messages = searchGoogle("adadflkjl", apiKey, cseKey)
assertThat(messages[0], "not found").all {
isInstanceOf(ErrorMessage::class.java)
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) {
// Avoid displaying api keys in CI logs
if ("true" == System.getenv("CI")) {

View 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>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="tests">
<test name="full">
<suite name="testng">
<test name="all">
<packages>
<package name="net.thauvin.erik.mobibot.*"/>
</packages>

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
#Fri Sep 16 14:23:24 PDT 2022
version.buildmeta=544
#Fri Sep 16 21:07:43 PDT 2022
version.buildmeta=574
version.major=0
version.minor=8
version.patch=0
version.prerelease=rc
version.project=mobibot
version.semver=0.8.0-rc+544
version.semver=0.8.0-rc+574