Skip to content

Commit 245873b

Browse files
committed
✅ Guard the my/routes manifest snake_case wire contract
The acceptance test deserializes the response into the C# record, which is casing-agnostic, so it would not catch a regression of the emitted field names. Add a serialization test asserting RouteManifestEntry emits snake_case even under a camelCase policy (as the Monitoring instance uses), pinning the contract that [JsonPropertyName] enforces.
1 parent 97f3806 commit 245873b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#nullable enable
2+
namespace ServiceControl.Infrastructure.Tests.Auth;
3+
4+
using System.Text.Json;
5+
using NUnit.Framework;
6+
using ServiceControl.Infrastructure.Auth;
7+
8+
[TestFixture]
9+
class RouteManifestEntrySerializationTests
10+
{
11+
// The my/routes manifest must have ONE wire shape across instances. The Primary instance
12+
// serializes snake_case and the Monitoring instance camelCase, so RouteManifestEntry pins its
13+
// field names with [JsonPropertyName]. This test guards that contract: even under a camelCase
14+
// policy (as on the Monitoring host) the emitted names stay snake_case, so a client merging both
15+
// instances never silently drops the differently-cased entries.
16+
[Test]
17+
public void Emits_snake_case_field_names_even_under_a_camelCase_policy()
18+
{
19+
var json = JsonSerializer.Serialize(
20+
new RouteManifestEntry("GET", "/api/errors"),
21+
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
22+
23+
Assert.That(json, Does.Contain("\"method\""));
24+
Assert.That(json, Does.Contain("\"url_template\""));
25+
Assert.That(json, Does.Not.Contain("urlTemplate"));
26+
}
27+
}

0 commit comments

Comments
 (0)