Skip to content

Commit

Permalink
Tweak snapshot display
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 6, 2025
1 parent b828b9c commit 640eb96
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 72 deletions.
20 changes: 10 additions & 10 deletions tests/testthat/_snaps/provider-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
# Azure request headers are generated correctly

Code
req$headers
str(req$headers)
Output
<httr2_headers>
api-key: <REDACTED>
<httr2_headers>
$ api-key: chr "key"

---

Code
req$headers
str(req$headers)
Output
<httr2_headers>
Authorization: <REDACTED>
<httr2_headers>
$ Authorization: chr "Bearer token"

---

Code
req$headers
str(req$headers)
Output
<httr2_headers>
api-key: <REDACTED>
Authorization: <REDACTED>
<httr2_headers>
$ api-key : chr "key"
$ Authorization: chr "Bearer token"

# service principal authentication requests look correct

Expand Down
77 changes: 23 additions & 54 deletions tests/testthat/_snaps/provider-cortex.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,68 +30,37 @@
# Cortex API requests are generated correctly

Code
list(url = req$url, headers = req$headers, body = req$body$data)
req$url
Output
$url
[1] "https://testorg-test_account.snowflakecomputing.com/api/v2/cortex/analyst/message"
$headers

---

Code
req$headers
Output
<httr2_headers>
Authorization: <REDACTED>
X-Snowflake-Authorization-Token-Type: <REDACTED>
$body
$body$messages
$body$messages[[1]]
$body$messages[[1]]$role
[1] "user"
$body$messages[[1]]$content
$body$messages[[1]]$content[[1]]
$body$messages[[1]]$content[[1]]$type
[1] "text"
$body$messages[[1]]$content[[1]]$text
[1] "Tell me about my data."
$body$stream
[1] FALSE
$body$semantic_model_file
[1] "@my_db.my_schema.my_stage/model.yaml"

---

Code
req$body$data
print_json(req$body$data)
Output
$messages
$messages[[1]]
$messages[[1]]$role
[1] "user"
$messages[[1]]$content
$messages[[1]]$content[[1]]
$messages[[1]]$content[[1]]$type
[1] "text"
$messages[[1]]$content[[1]]$text
[1] "Tell me about my data."
$stream
[1] FALSE
$semantic_model_file
[1] "@my_db.my_schema.my_stage/model.yaml"
{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Tell me about my data."
}
]
}
],
"stream": false,
"semantic_model_file": "@my_db.my_schema.my_stage/model.yaml"
}

9 changes: 6 additions & 3 deletions tests/testthat/test-provider-azure.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ test_that("Azure request headers are generated correctly", {
credentials = default_azure_credentials("key")
)
req <- chat_request(p, FALSE, list(turn))
expect_snapshot(req$headers, transform = transform_user_agent)
attr(req$headers, "redact") <- character()
expect_snapshot(str(req$headers))

# Token.
p <- ProviderAzure(
Expand All @@ -79,7 +80,8 @@ test_that("Azure request headers are generated correctly", {
credentials = default_azure_credentials("", "token")
)
req <- chat_request(p, FALSE, list(turn))
expect_snapshot(req$headers, transform = transform_user_agent)
attr(req$headers, "redact") <- character()
expect_snapshot(str(req$headers))

# Both.
p <- ProviderAzure(
Expand All @@ -90,7 +92,8 @@ test_that("Azure request headers are generated correctly", {
credentials = default_azure_credentials("key", "token")
)
req <- chat_request(p, FALSE, list(turn))
expect_snapshot(req$headers, transform = transform_user_agent)
attr(req$headers, "redact") <- character()
expect_snapshot(str(req$headers))
})

test_that("service principal authentication requests look correct", {
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-provider-cortex.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ test_that("Cortex API requests are generated correctly", {
model_file = "@my_db.my_schema.my_stage/model.yaml"
)
req <- chat_request(p, FALSE, list(turn))
expect_snapshot(
list(url = req$url, headers = req$headers, body = req$body$data),
transform = transform_user_agent
)
expect_snapshot(req$body$data)
expect_snapshot(req$url)
expect_snapshot(req$headers)
expect_snapshot(print_json(req$body$data))
})

test_that("a simple Cortex chatbot works", {
Expand Down

0 comments on commit 640eb96

Please sign in to comment.