Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utilities for testing with UUIDs #159

Open
jmalloc opened this issue Nov 19, 2020 · 2 comments
Open

Add utilities for testing with UUIDs #159

jmalloc opened this issue Nov 19, 2020 · 2 comments

Comments

@jmalloc
Copy link
Member

jmalloc commented Nov 19, 2020

It's common to need to generate UUIDs for use within messages within tests, however when there is a test failure due to an incorrect UUID it can be hard to understand what the UUID refers to.

We could add a UUID generator to Test that obtains a UUID by "name", and logged about the UUIDs it generates in the test output. We could even annotate the diff output next to a UUID to show their "name".

I'm imagining usage something like the following:

test := testkit.Begin(t, app)
depositID := testkit.UUID("deposit ID")

test.Expect(
    testkit.ExecuteCommand(StartDeposit{
        TransactionID: depositID,
    }),
    assert.EventRecorded(DepositStarted{
        TransactionID: depositID,
    }),
)

This would result in log output something like:

Generated UUID for "deposit ID" (2a5c9fe5-29af-4f5b-a51d-8c306cfea9af)
@jmalloc
Copy link
Member Author

jmalloc commented Nov 19, 2020

We could even annotate the diff output next to a UUID to show their "name".

Perhaps this could be a more generic "annotation" system. It's probably worth looking into existing test-vector generation libraries too.

@jmalloc
Copy link
Member Author

jmalloc commented Aug 19, 2024

Low-level support for annotations is being added to dogmatiq/dapper in dogmatiq/dapper#68, so if we could provide a facade in testkit that sets up annotations when rendering message diffs that should get the job done. I don't think we actually need anything UUID specific, so now I'm thinking of an interface something like:

depositID := uuid.New() // regular UUID library
test := testkit.Begin(t, app)
test.Annotate(depositID, "the deposit ID")
test.Expect(...)

We'd have to come up with some rules for equality, and they'd have to work even if a value was serialized/deserialized again (that is, probably can't be a shallow comparison).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant