Skip to content

Instantly share code, notes, and snippets.

@zorn
Last active September 26, 2021 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorn/02e4e44d726fdd9b42f10fb10bd02407 to your computer and use it in GitHub Desktop.
Save zorn/02e4e44d726fdd9b42f10fb10bd02407 to your computer and use it in GitHub Desktop.
How we use `Kernal.match/2` to validate that a list has an expected value.
# chunk of code from our tests where we validated that an expected metric was captured
# heavily edited out company info
metrics =
capture_metrics(fn ->
with_trace(fn ->
assert {:ok, _result} = Work.stuff()
end)
end)
assert Enum.any?(
metrics,
&match?(
%{
metadata: %{
result_id: ^result_id,
status: :success
},
topic: "engine.work.reconcile"
},
&1
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment