tests/testthat/test-utils-auth.R

# tests use `chat_openai()` to verify environments flow through correctly

test_that("api_key is deprecated", {
  expect_snapshot(chat <- chat_openai_compatible_test(api_key = "abc"))
  expect_equal(chat$get_provider()@credentials(), "Bearer abc")
})

test_that("errors if both credentials and api_key are provided", {
  expect_snapshot(
    chat_openai_compatible_test(credentials = "abc", api_key = "def"),
    error = TRUE
  )
})

test_that("verifies all properties of credentials", {
  expect_snapshot(error = TRUE, {
    chat_openai_test(credentials = 1)
    chat_openai_test(credentials = \(a, b) a + b)
    chat_openai_test(credentials = \() 1)
  })
})

Try the ellmer package in your browser

Any scripts or data that you put into this service are public.

ellmer documentation built on July 14, 2026, 1:07 a.m.