-
Notifications
You must be signed in to change notification settings - Fork 228
#981 migrate to ktor v2 #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#981 migrate to ktor v2 #1018
Conversation
singleTeamBotToken was causing validation issues in the tests, had to remove it not sure what was causing this
| val appConfig = AppConfig.builder() | ||
| .slack(Slack.getInstance(slackConfig)) | ||
| .signingSecret(signingSecret) | ||
| .singleTeamBotToken(AuthTestMockServer.ValidToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line had to be removed from the tests, I'm not sure how this was passing in the past.
Maybe someone can let me know if the tests need to be refactored to include this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WilliamBergamin This should not be changed. To me, it is a bit surprising to see the CI builds with the current change succeed but I found that Ktor v2 testing behaves a bit differently. Can you change all the tests this way?
diff --git a/bolt-ktor/src/test/kotlin/test_locally/app/commands/test.kt b/bolt-ktor/src/test/kotlin/test_locally/app/commands/test.kt
index 40f2f697..87ba6b00 100644
--- a/bolt-ktor/src/test/kotlin/test_locally/app/commands/test.kt
+++ b/bolt-ktor/src/test/kotlin/test_locally/app/commands/test.kt
@@ -20,30 +20,31 @@ import util.AuthTestMockServer
import kotlin.test.Test
import kotlin.test.assertEquals
-const val signingSecret = "secret"
-val authTestMockServer = AuthTestMockServer()
-val slackConfig = SlackConfig()
+class KtorAppCommandTest {
+ private val signingSecret = "secret"
+ private val authTestMockServer = AuthTestMockServer()
+ private val slackConfig = SlackConfig()
-fun Application.main() {
- val appConfig = AppConfig.builder()
+ // Since Ktor v2, this function override needs to be inside the test class
+ private fun Application.main() {
+ val appConfig = AppConfig.builder()
.slack(Slack.getInstance(slackConfig))
.signingSecret(signingSecret)
+ .singleTeamBotToken(AuthTestMockServer.ValidToken)
.build()
- val app = App(appConfig)
+ val app = App(appConfig)
- app.command("/weather") { _, ctx ->
- ctx.ack("This a clear sunny day!")
- }
+ app.command("/weather") { _, ctx ->
+ ctx.ack("This a clear sunny day!")
+ }
- val requestParser = SlackRequestParser(app.config())
- routing {
- post("/slack/events") {
- respond(call, app.run(toBoltRequest(call, requestParser)))
+ val requestParser = SlackRequestParser(app.config())
+ routing {
+ post("/slack/events") {
+ respond(call, app.run(toBoltRequest(call, requestParser)))
+ }
}
}
-}
-
-class KtorAppCommandTest {
@Before
fun setUp() {class KtorAppCommandTest {
private val signingSecret = "secret"
private val authTestMockServer = AuthTestMockServer()
private val slackConfig = SlackConfig()
// Since Ktor v2, this function override needs to be inside the test class
private fun Application.main() {
val appConfig = AppConfig.builder()
.slack(Slack.getInstance(slackConfig))
.signingSecret(signingSecret)
.singleTeamBotToken(AuthTestMockServer.ValidToken)
.build()
val app = App(appConfig)
app.command("/weather") { _, ctx ->
ctx.ack("This a clear sunny day!")
}
val requestParser = SlackRequestParser(app.config())
routing {
post("/slack/events") {
respond(call, app.run(toBoltRequest(call, requestParser)))
}
}
}
@Before
fun setUp() {
authTestMockServer.start()
slackConfig.methodsEndpointUrlPrefix = authTestMockServer.methodsEndpointPrefix
}
@After
fun tearDown() {
authTestMockServer.stop()
}
Codecov Report
@@ Coverage Diff @@
## main #1018 +/- ##
============================================
+ Coverage 76.68% 76.70% +0.01%
- Complexity 3688 3689 +1
============================================
Files 403 403
Lines 11121 11121
Branches 1111 1111
============================================
+ Hits 8528 8530 +2
+ Misses 1922 1921 -1
+ Partials 671 670 -1
Continue to review full report at Codecov.
|
seratch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check my suggestion for the test changes? Once they are resolved, this PR looks great to me!
ktor v2 tests seem to behave differently then v1. The application being tested was placed within the Test class to allow proper testing. As this was done the test files were renamed to be more descriptive
Ktor released a new major version 2.0.x this change was not completely backwards compatible more details in the related issue #981
The changes in this PR allow to migrate Ktor used in bolt-ktor from 1.6.8 to 2.0.3
Category (place an
xin each of the[ ])Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to the those rules.