Does anyone have suggestions on how to debug my is...
# pact-net
v
Does anyone have suggestions on how to debug my issue better? I keep getting a
500
request mismatch from Pact. I'm aware that my expected request is not the same, but I am trying to write an SDK contract as a demo and reverse-engineering the request for my test setup. Deleted some actual data for privacy purposes.
Copy code
"{\"error\":\"Request-Mismatch : HttpRequest { method: \\\"POST\\\", path: \\\"/\\\", query: Some({\\\"api-version\\\": [\\\"1.0\\\"]}), headers: Some({\\\"user-agent\\\": [\\\"\\\"], \\\"content-length\\\": [\\\"848\\\"], \\\"connection\\\": [\\\"Keep-Alive\\\"], \\\"authorization\\\": [\\\"Bearer Access-Token\\\"], \\\"host\\\": [\\\"127.0.0.1:59176\\\"], \\\"expect\\\": [\\\"100-continue\\\"], \\\"content-type\\\": [\\\"application/json\\\"], \\\"x-mt-secondaryid\\\": [\\\"\\\"]}), body: Present", Some(ContentType { main_type: \\\"application\\\", sub_type: \\\"json\\\", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }\"}"
It's hard to figure out what's not matching
For future people who aren't idiots like me πŸ˜… . Debug mode is the best πŸ˜„
m
The errors should really be formatted. Sounds like we need to improve the output messages in Pact .Net. @Adam Rodger (pact-net) do you just print the errors verbatim in Pact .NET or take the JSON errors from the core and format them? I can raise a feature request if the former
v
Do you know of how to do a body partial matcher? I figured out my issue, but now I'm trying to say all these key-values should match except for this one key (which I don't necessarily care).
E.g.
Copy code
Expected '{\"eventMessageId\":{\"pact:matcher:type\":\"type\",\"value\":\"string\"},
The actual is
Copy code
"eventMessageId\":\"d5f8868f-baa1-4f6c-9166-2056c374d6f5\"
I'm assuming that it works, but the error just says my entire body doesn't match
m
What does your test setup look like? That’s probably going to be easier to share how to correct than from the output logs
v
Copy code
_pact.UponReceiving("a POST request to create an Audit record").
                Given("Transformed Audit Request Model").
                WithRequest(<http://HttpMethod.Post|HttpMethod.Post>, "/auditing/emitter/api/audit").
                WithQuery("api-version", "1.0").
                WithHeader("user-agent", "UserAgent").
                WithHeader("authorization", "Bearer Access-Token").
                WithHeader("content-length", "848").
                WithHeader("content-type", "application/json").
                WithHeader("x-mt-secondaryid", Guid.Empty.ToString()).
                WithHeader("expect", "100-continue").
                WithHeader("connection","Keep-Alive").
                WithJsonBody(new
                {
                    EventMessageId = Match.Type("string"),
                    SessionId = auditRequestModel.SessionId,
                    SourceId = auditRequestModel.SourceId,
                    SecretId = auditRequestModel.SecretId,
                    UserId = auditRequestModel.UserId,
                    UserName = auditRequestModel.UserName,
                    AssetId = auditRequestModel.AssetId,
                    EventTypeId = auditRequestModel.EventTypeId,
                    EventDateTime = auditRequestModel.EventDateTime,
                    RawMessage = auditRequestModel.RawMessage,
                    Tags = auditRequestModel.Tags,
                    AnalyticData = auditRequestModel.AnalyticData
                }).
                WillRespond().WithStatus(HttpStatusCode.Accepted);
Copy code
_pact = Pact.V3("Secret Server API", "Auditing Platform Service", new PactConfig()
            {
            PactDir = $"{Directory.GetParent(Directory.GetCurrentDirectory())}",
            LogLevel = PactLogLevel.Debug
            }).WithHttpInteractions();

var auditRequestModel = _auditTransformer.TransformIEventQueueToAuditModel(displayItem);
Then I have some substitutes in-between but they're just to make the class instantiate properly
I'm fairly certain its the
EventMessageId
because my TransformIEventQueueToAuditModel adds a random Guid to the object before sending. Hence the mocked and the actual differ on that specific field
In Go there's a Pact.Like (if I recall), and in Ruby. I can't seem to find the equivalent in C#
This is the weird mismatch:
Copy code
[BodyMismatch { path: "$", expected: 
Some(b"[\"analyticData\",\"assetId\",\"eventDateTime\",\"eventMessageId\",\"eventTypeId\",\"rawMessage\",\"secretId\",\"sessionId\",\"sourceId\",\"tags\",\"userId\",\"userName\"]"), 
actual: Some(b"[\"assetId\",\"eventDateTime\",\"eventMessageId\",\"eventTypeId\",\"rawMessage\",\"secretId\",\"sourceId\",\"tags\",\"userId\",\"userName\"]"), 
mismatch: "Expected a Map with keys analyticData, assetId, eventDateTime, eventMessageId, eventTypeId, rawMessage, secretId, sessionId, sourceId, tags, userId, userName but received one with keys assetId, eventDateTime, eventMessageId, eventTypeId, rawMessage, secretId, sourceId, tags, userId, userName" }]
All the debug logs say my fields match but my keys don't match?
m
It seems your request is missing the following keys:
analyticData
and
sessionId
v
Awesome. Another set of eyes helped. I should match each one carefully next time
πŸ‘ 1
It caught something I was missing too πŸ™‚ .
πŸŽ‰ 1
m
No worries! I think it should be printing out more human friendly errors
Might be worth raising a feature request on Pact .NET to print them out better