If I have a DTO which uses a `*time.Time` value wi...
# pact-go
j
If I have a DTO which uses a
*time.Time
value within a struct, how can I tell the
dsl.Matcher
to marshal it to a string or nil as go would? As of now, it's sending
{}
which is unable to be unmarshalled.
I should probably mention that I'm using pact-go version 1.7.0 due to v2 only being marked as having beta stability.
m
It needs to be serialised into a string, like you would if you sent it over the wire. P.S. v2 is no longer beta
j
the readme here: https://github.com/pact-foundation/pact-go/blob/master/README.md specifies that its stability is
beta
, is that not updated?
Copy code
Specification Compatibility
Version 	Stable 	Spec Compatibility 	Install
2.0.x 	Beta 	2, 3 	See installation
m
Try a refresh ๐Ÿ˜†
j
Hey look at that ๐Ÿ˜›
m
(I only dropped the unstable tag last night, and forgot about that table)
j
Ah that's good to know!
The time itself is sent as a string over the wire but when the matcher creates an example object, the object it makes contains the time property as a JSON object. We're using oapi-codegen to fill in our provider models.
๐Ÿ‘ 1
m
How are you using the matcher object?
j
We're also doing something similar to unmarshal the time from the consumer end. Perhaps the advised workflow is to create an intermediate object for use only with pact?
Let me grab an example. Just a second.
๐Ÿ‘ 1
minor comment update
m
Sorry, I had a meeting
How are you passing it to the Pact matchers though? Are you using the struct tags?
j
dsl.Match(ExampleJSONObject{})
is what I have been attempting to use
m
got it
I can see why it might not work, because I donโ€™t think the
Match
feature is clever enough to first serialise the
time.Time
thing
(iโ€™m just looking at the implementation of that now)
OK unfortunately it looks like it wonโ€™t work. The
Match
function is quite primitive. It could probably be made to be less so if you were up for some tinkering?
j
is this function found within v2 as well?
m
yes it should be (but would behave the same)
j
gotcha, if I put in a PR, then it'll go against v2
๐Ÿ‘ 1
for now, it seems like the best workaround is probably going to be to use the
StructMatcher
, does that sound correct?
๐Ÿ‘ 1
m
yep, I think so
j
a related question: is there an easy way to specify that a property within a StructMatcher is able to be nil?
m
It has to be two separate tests
see howtooptional
j
perfect. thank you.
๐Ÿ™Œ 1