mirror of
https://github.com/apple/pkl.git
synced 2026-03-31 22:23:18 +02:00
Add support for HTTP rewrites (#1062)
This adds a new configuration option for the HTTP client to replace URI prefixes when making outbound calls. Follows the design of https://github.com/apple/pkl-evolution/pull/17
This commit is contained in:
@@ -119,6 +119,36 @@ class CliMainTest {
|
||||
assertThat(ex.message).contains("URI `file:my file.txt` has invalid syntax")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid rewrites -- non-HTTP URI`() {
|
||||
val ex =
|
||||
assertThrows<BadParameterValue> {
|
||||
rootCmd.parse(arrayOf("eval", "--http-rewrite", "foo=bar", "mymodule.pkl"))
|
||||
}
|
||||
assertThat(ex.message)
|
||||
.contains("Rewrite rule must start with 'http://' or 'https://', but was 'foo'")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid rewrites -- invalid URI`() {
|
||||
val ex =
|
||||
assertThrows<BadParameterValue> {
|
||||
rootCmd.parse(arrayOf("eval", "--http-rewrite", "https://foo bar=baz", "mymodule.pkl"))
|
||||
}
|
||||
assertThat(ex.message).contains("Rewrite target `https://foo bar` has invalid syntax")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid rewrites -- doesn't end with slash`() {
|
||||
val ex =
|
||||
assertThrows<BadParameterValue> {
|
||||
rootCmd.parse(
|
||||
arrayOf("eval", "--http-rewrite", "http://foo.com=https://bar.com", "mymodule.pkl")
|
||||
)
|
||||
}
|
||||
assertThat(ex.message).contains("Rewrite rule must end with '/', but was 'http://foo.com'")
|
||||
}
|
||||
|
||||
private fun makeInput(tempDir: Path, fileName: String = "test.pkl"): String {
|
||||
val code = "x = 1"
|
||||
return tempDir.resolve(fileName).writeString(code).toString()
|
||||
|
||||
Reference in New Issue
Block a user