Skip to content

Commit c1be722

Browse files
author
Krystian Panek
committed
DSL impr
1 parent abbbea7 commit c1be722

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/kotlin/com/cognifide/gradle/environment/EnvironmentPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ class EnvironmentPlugin : CommonDefaultPlugin() {
2424

2525
private fun Project.setupTasks() = tasks {
2626
val resolve = register<EnvironmentResolve>(EnvironmentResolve.NAME)
27+
val hosts = register<EnvironmentHosts>(EnvironmentHosts.NAME)
2728

2829
val down = register<EnvironmentDown>(EnvironmentDown.NAME)
2930
val destroy = register<EnvironmentDestroy>(EnvironmentDestroy.NAME) {
3031
dependsOn(down)
3132
}
3233
val up = register<EnvironmentUp>(EnvironmentUp.NAME) {
33-
mustRunAfter(resolve, down, destroy)
34+
mustRunAfter(hosts, resolve, down, destroy)
3435
}
3536
val restart = register<EnvironmentRestart>(EnvironmentRestart.NAME) {
3637
dependsOn(down, up)
@@ -48,7 +49,6 @@ class EnvironmentPlugin : CommonDefaultPlugin() {
4849
register<EnvironmentReload>(EnvironmentReload.NAME) {
4950
mustRunAfter(up)
5051
}
51-
register<EnvironmentHosts>(EnvironmentHosts.NAME)
5252

5353
// Runtime lifecycle
5454

src/main/kotlin/com/cognifide/gradle/environment/health/HealthChecker.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class HealthChecker(val environment: EnvironmentExtension) {
8888
/**
8989
* Check URL using specified criteria (HTTP options and e.g text & status code assertions).
9090
*/
91+
fun http(checkName: String, url: String, statusCode: Int = HttpStatus.SC_OK) {
92+
http(checkName, url) { respondsWith(statusCode) }
93+
}
94+
9195
fun http(checkName: String, url: String, containedText: String, statusCode: Int = HttpStatus.SC_OK) {
9296
http(checkName, url) { containsText(containedText, statusCode) }
9397
}

src/main/kotlin/com/cognifide/gradle/environment/health/HttpCheck.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class HttpCheck(val url: String) {
2222

2323
// Shorthand methods for checking responses
2424

25+
fun respondsWith(statusCode: Int) {
26+
check { response ->
27+
checkStatus(response, statusCode)
28+
}
29+
}
30+
31+
fun respondsOk() = respondsWith(HttpStatus.SC_OK)
32+
2533
fun containsText(text: String, statusCode: Int = HttpStatus.SC_OK) {
2634
check { response ->
2735
checkStatus(response, statusCode)

0 commit comments

Comments
 (0)