Skip to content

Improve RandomUUID example generator #70

@surpher

Description

@surpher

🗣 Context

RandomUUID ExampleGenerator is only writing a simple UUID, eg: 22fa4d123c17471bbb6ab57aaa5fb24f into a Pact file. This makes it a bit annoying when expecting uppercased and/or dash separated value.

As an example:

// Let's say Swagger says the value will be a UUID in dashed and uppercased format
// Pact test
// -- code...
body: [
  "id": ExampleGenerator.RandomUUID() // eg: "BDA52033-F0F1-4EC3-8CA4-E04D71572913"
]
// -- code...

PactSwift generates a Pact interaction with the id value of eg: BDA52033-F0F1-4EC3-8CA4-E04D71572913 and passes it to libpact_mock_server_ffi. When FFI is told to generate and write the interactions in a Pact file, a different UUID is generated and written in simple format type, eg: fda98152f0f14ce38aa4b04a54132913.

Because of the above an encodable Swift model that defines a property of type Foundation.UUID fails automatic serialisation unless a custom encodable initialiser is provided. But that could/should be avoided.

💬 Narrative

When I use ExampleGenerator.RandomUUID()
I want to set a specific format
So that the client validation is easier

📝 Notes

Even if defining an ExampleGenerator and preparing a Pact file with a specific format for UUID, libpact_mock_server_ffi returns a different UUID in simple format. Will need to work with pact-foundation/pact-reference to support this.

As a workaround until this is implemented, a Matcher.RegexLike(_:term:) can be used instead and providing the UUID value in the expected format.

🎨 Design

N/A

✅ Acceptance Criteria

GIVEN I use ExampleGenerator.RandomUUID() in a pact test
WHEN I run a pact test
THEN MockService responds with something like BDA52033-F0F1-4EC3-8CA4-E04D71572913

GIVEN I use ExampleGenerator.RandomUUID(.uppercaseDashed) in a pact test
WHEN I run a pact test
THEN MockService responds with something like BDA52033-F0F1-4EC3-8CA4-E04D71572913

GIVEN I use ExampleGenerator.RandomUUID(.dashed) in a pact test
WHEN I run a pact test
THEN MockService responds with something like bda52033-f0f1-4ec3-8ca4-e04d71572913

GIVEN I use ExampleGenerator.RandomUUID(.simple) in a pact test
WHEN I run a pact test
THEN MockService responds with something like bda52033f0f14ec38ca4e04d71572913

🚫 Out of Scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthacktoberfestA tag describing the issue or pull request is considered part of hacktoberfet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions