Hello, I have a question about enums in contract t...
# pact-python
p
Hello, I have a question about enums in contract tests. My use-case is that I'd like to tests messages being sent in event-driven system (messaging) between publisher and subscriber. Imagine that I'm sending these enums as a part of message
Copy code
class TestEnumV1(str, Enum):
    OPTION_1 = "option_1"
    OPTION_2 = "option_2"
    OPTION_3 = "option_3"

class TestEnumV2(str, Enum):
    OPTION_1 = "option_1"
    OPTION_2 = "option_2"
    OPTION_3 = "option_3"
    OPTION_4 = "option_4"
Note that
TestEnumV2
has extra
OPTION_4
. I'm sending these messages as JSONs so it will be serialized as "option_4" string. Now
TestEnumV1
and
TestEnumV2
are not compatible because if publisher sends
"option_4"
to a subscriber understanding only
TestEnumV1
it will fail because subscriber will not know that value in
TestEnumV1
. However, if I write consumer matcher as
pact.Like(TestEnumV1.OPTION_1)
it will happily accept any string. I can write a regex for it
pact.Term(r"^option_1|option_2|option_3$", "option_1")
which would resolve it on consumer side. But what should I do on provider side? Should I generate and test message with every enum value possible? Is this (consumer and provider parts) how it should be done?