Issues testing/mocking calls that require crypto/UUID

Hey, I’m trying to test a function that uses the elixir_uuid library, which in turn requires erlang’s crypto library. When I run my tests, it’s not able to find the UUID namespace. During the compile phase before running the tests, I get the errors similar to the following, which is most likely the cause of this error:

Warning: :crypto.hash/2 defined in application :crypto is used by the current application but the current application does not depend on :crypto. To fix this, you must do one of:

  1. If :crypto is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

But :crypto is added under :extra_applications in my mix.exs, and it works fine when I’m running in development and production. Is there an extra step I need to take to get this working in the test environment?

  def application do
      mod: {MyApp.Application, []},
      extra_applications: [:logger, :runtime_tools, :crypto]
1 Like

Hi @jfacoustic :wave:t2: !

I suppose the error comes from elixir_uuid not your application. I think the only way to fix it properly is to have elixir_uuid added :crypto to its :extra_applications.

There is an open PR zyro/elixir-uuid#56 that would that (hanging there for a year now)

1 Like

Added this to the mix.deps and it worked, although the actual reason for the test failing is that I accidentally used fn _ -> ... end instead of fn -> ... end

      {:elixir_uuid, git: "", branch: "extra-apps"},