Skip to content

Commit

Permalink
Check texts
Browse files Browse the repository at this point in the history
  • Loading branch information
pun-ky committed Apr 29, 2021
1 parent 7f10675 commit 7591e57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
30 changes: 5 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ plugins {
id("org.jetbrains.dokka") version "1.4.0-rc"
id("com.gradle.plugin-publish") version "0.11.0"
id("io.gitlab.arturbosch.detekt") version "1.6.0"
id("com.jfrog.bintray") version "1.8.4"
id("net.researchgate.release") version "2.8.1"
id("com.github.breadmoirai.github-release") version "2.2.10"
}
Expand Down Expand Up @@ -107,7 +106,7 @@ tasks {
}

named("afterReleaseBuild") {
dependsOn("bintrayUpload", "publishPlugins")
dependsOn("publishPlugins")
}

named("githubRelease") {
Expand Down Expand Up @@ -154,8 +153,10 @@ gradlePlugin {
}
}

val pluginTags = listOf("sftp", "smb", "ssh", "progress", "file watcher", "file download", "file upload",
"gui notification", "gradle-plugin", "gradle plugin development")
val pluginTags = listOf(
"sftp", "smb", "ssh", "progress", "file watcher", "file download", "file upload",
"gui notification", "gradle-plugin", "gradle plugin development"
)

pluginBundle {
website = "https://github.com/wttech/gradle-common-plugin"
Expand All @@ -164,27 +165,6 @@ pluginBundle {
tags = pluginTags
}

bintray {
user = (project.findProperty("bintray.user") ?: System.getenv("BINTRAY_USER"))?.toString()
key = (project.findProperty("bintray.key") ?: System.getenv("BINTRAY_KEY"))?.toString()
setPublications("mavenJava")
with(pkg) {
repo = "maven-public"
name = "gradle-common-plugin"
userOrg = "wttech"
setLicenses("Apache-2.0")
vcsUrl = "https://github.com/wttech/gradle-common-plugin.git"
setLabels(*pluginTags.toTypedArray())
with(version) {
name = project.version.toString()
desc = "${project.description} ${project.version}"
vcsTag = project.version.toString()
}
}
publish = (project.findProperty("bintray.publish") ?: "true").toString().toBoolean()
override = (project.findProperty("bintray.override") ?: "false").toString().toBoolean()
}

githubRelease {
owner("wttech")
repo("gradle-common-plugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ class HealthChecker(val common: CommonExtension) {
fun http(checkName: String, url: String, criteria: HttpCheck.() -> Unit) = check(checkName) {
var result: Any? = null
common.http {
val check = HttpCheck(url)
apply(httpOptions)

val check = HttpCheck(url).apply(criteria)
apply(check.options)
check.apply(criteria)

request(check.method, check.url) { response ->
result = "${check.method} ${check.url} -> ${response.statusLine}"
check.checks.forEach { it(response) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ class HttpCheck(val url: String) {

fun respondsOk() = respondsWith(HttpStatus.SC_OK)

fun containsText(text: String, statusCode: Int = HttpStatus.SC_OK) {
fun containsText(text: String, statusCode: Int = HttpStatus.SC_OK) = containsTexts(listOf(text), statusCode)

fun containsTexts(vararg texts: String, statusCode: Int = HttpStatus.SC_OK) = containsTexts(texts.asIterable(), statusCode)

fun containsTexts(texts: Iterable<String>, statusCode: Int = HttpStatus.SC_OK) {
check { response ->
checkStatus(response, statusCode)
checkText(response, text)
checkTexts(response, texts)
}
}
}
12 changes: 8 additions & 4 deletions src/main/kotlin/com/cognifide/gradle/common/http/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,15 @@ open class HttpClient(private val common: CommonExtension) {
throw ResponseException("Unexpected response status detected: ${response.statusLine}")
}

fun checkText(response: HttpResponse, containedText: String, ignoreCase: Boolean = true) {
fun checkText(response: HttpResponse, containedText: String, ignoreCase: Boolean = true) = checkTexts(response, listOf(containedText), ignoreCase)

fun checkTexts(response: HttpResponse, containedTexts: Iterable<String>, ignoreCase: Boolean = true) {
val text = asString(response)
if (!text.contains(containedText, ignoreCase)) {
logger.debug("Actual text:\n$text")
throw ResponseException("Response does not contain text: $containedText")
containedTexts.forEach { containedText ->
if (!text.contains(containedText, ignoreCase)) {
logger.debug("Actual text:\n$text")
throw ResponseException("Response does not contain text: $containedText")
}
}
}

Expand Down

0 comments on commit 7591e57

Please sign in to comment.