Files
fil/docs/snippets/r/plugins/plugin_testing.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

35 lines
893 B
Markdown

<!-- snippet:syntax-only -->
```r title="R"
library(kreuzberg)
library(testthat)
uppercase_processor <- function(result) {
result$content <- toupper(result$content)
return(result)
}
test_that("uppercase processor uppercases content", {
fake_result <- list(
content = "hello world",
mime_type = "text/plain",
metadata = list()
)
processed <- uppercase_processor(fake_result)
expect_equal(processed$content, "HELLO WORLD")
})
test_that("post processor registers and runs", {
register_post_processor("uppercase", uppercase_processor)
on.exit(unregister_post_processor("uppercase"), add = TRUE)
config <- list(postprocessor = list(enabled = TRUE))
json <- extract_bytes_sync(
charToRaw("hello world"), "text/plain", config
)
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
expect_match(result$content, "HELLO WORLD", fixed = TRUE)
})
```