I am trying to write some integration tests. What I want to achieve is to setup a couple of fake URLs to emulate third party services. I want to know if it is possible to set dynamically URL path for test. For example I have this code
In a base file for the test I have this
override lazy val port = 1234
val myappTestConf = Map (
"app.twilio.lookups" -> s"https://localhost:$port",
)
override lazy val port = 1234
implicit override lazy val app: FakeApplication =
FakeApplication(
additionalConfiguration = myappTestConf
)
and then in a more specific file I have this
val getLookupPhoneUrl = s"${phoneNumber}"
implicit override lazy val app: FakeApplication =
FakeApplication(
additionalConfiguration = myappTestConf,
withRoutes = {
case ("GET", `getLookupPhoneUrl`) => Action(testLookupPhone(_))
}
)
The problem that I have is that this code does not compile because in the second file the phoneNumber has not been setted up, but I would like to set up dinamically, is that possible?
Thank you
One of the members of the team solved this with regex. Here is the answer
on the test files
val GetLookupPhone = """/v1/PhoneNumbers/([0-9\.\-]+)""".r
var phone: String = _
implicit override lazy val app: FakeApplication =
FakeApplication(
additionalConfiguration = educatinaTestConf,
withRoutes = {
case ("GET", GetLookupPhone(phone)) => Action(testLookupPhone(_, phone))
}
)
So then the route could be accessed if the route match the regex.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.