Skip to content

Commit df64264

Browse files
committed
test: verify a warning was logged
1 parent 49b492a commit df64264

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo-mcp-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ url.workspace = true
3333
[dev-dependencies]
3434
insta = { workspace = true }
3535
rstest = "0.25.0"
36+
tracing-test = "0.2.5"
3637

3738
[lints]
3839
workspace = true

crates/apollo-mcp-server/src/operations.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ mod tests {
10211021

10221022
use apollo_compiler::{Schema, parser::Parser, validation::Valid};
10231023
use rmcp::{model::Tool, serde_json};
1024+
use tracing_test::traced_test;
10241025

10251026
use crate::{
10261027
custom_scalar_map::CustomScalarMap,
@@ -2015,8 +2016,8 @@ mod tests {
20152016
}
20162017

20172018
#[test]
2019+
#[traced_test]
20182020
fn unknown_type_should_be_any() {
2019-
// TODO: should this test that the warning was logged?
20202021
let operation = Operation::from_document(
20212022
RawOperation {
20222023
source_text: "query QueryName($id: FakeType) { id }".to_string(),
@@ -2035,6 +2036,16 @@ mod tests {
20352036
.unwrap();
20362037
let tool = Tool::from(operation);
20372038

2039+
// Verify that a warning was logged
2040+
logs_assert(|lines: &[&str]| {
2041+
lines
2042+
.iter()
2043+
.filter(|line| line.contains("WARN"))
2044+
.any(|line| line.contains("Type not found in schema name=\"FakeType\""))
2045+
.then_some(())
2046+
.ok_or("Expected warning about unknown type in logs".to_string())
2047+
});
2048+
20382049
insta::assert_debug_snapshot!(tool, @r###"
20392050
Tool {
20402051
name: "QueryName",
@@ -2063,8 +2074,8 @@ mod tests {
20632074
}
20642075

20652076
#[test]
2077+
#[traced_test]
20662078
fn custom_scalar_without_map_should_be_any() {
2067-
// TODO: should this test that the warning was logged?
20682079
let operation = Operation::from_document(
20692080
RawOperation {
20702081
source_text: "query QueryName($id: RealCustomScalar) { id }".to_string(),
@@ -2083,6 +2094,16 @@ mod tests {
20832094
.unwrap();
20842095
let tool = Tool::from(operation);
20852096

2097+
// Verify that a warning was logged
2098+
logs_assert(|lines: &[&str]| {
2099+
lines
2100+
.iter()
2101+
.filter(|line| line.contains("WARN"))
2102+
.any(|line| line.contains("custom scalars aren't currently supported without a custom_scalar_map name=\"RealCustomScalar\""))
2103+
.then_some(())
2104+
.ok_or("Expected warning about custom scalar without map in logs".to_string())
2105+
});
2106+
20862107
insta::assert_debug_snapshot!(tool, @r###"
20872108
Tool {
20882109
name: "QueryName",
@@ -2118,8 +2139,8 @@ mod tests {
21182139
}
21192140

21202141
#[test]
2142+
#[traced_test]
21212143
fn custom_scalar_with_map_but_not_found_should_error() {
2122-
// TODO: should this test that the warning was logged?
21232144
let operation = Operation::from_document(
21242145
RawOperation {
21252146
source_text: "query QueryName($id: RealCustomScalar) { id }".to_string(),
@@ -2138,6 +2159,20 @@ mod tests {
21382159
.unwrap();
21392160
let tool = Tool::from(operation);
21402161

2162+
// Verify that a warning was logged
2163+
logs_assert(|lines: &[&str]| {
2164+
lines
2165+
.iter()
2166+
.filter(|line| line.contains("WARN"))
2167+
.any(|line| {
2168+
line.contains(
2169+
"custom scalar missing from custom_scalar_map name=\"RealCustomScalar\"",
2170+
)
2171+
})
2172+
.then_some(())
2173+
.ok_or("Expected warning about custom scalar missing in logs".to_string())
2174+
});
2175+
21412176
insta::assert_debug_snapshot!(tool, @r###"
21422177
Tool {
21432178
name: "QueryName",

0 commit comments

Comments
 (0)