diff --git a/lib/avrogen/avro/types/union.ex b/lib/avrogen/avro/types/union.ex index 71753a3..4543d3c 100644 --- a/lib/avrogen/avro/types/union.ex +++ b/lib/avrogen/avro/types/union.ex @@ -66,11 +66,6 @@ defimpl CodeGenerator, for: Union do quote do (unquote_splicing(functions)) - - # This is not correct behaviour, but is the current behaviour of the library. - # We should remove this and return and error simply have a match failure in a - # future release - defp unquote(function_name)(value), do: value end end diff --git a/test/avro/types/union_test.exs b/test/avro/types/union_test.exs index df8ba68..978d06a 100644 --- a/test/avro/types/union_test.exs +++ b/test/avro/types/union_test.exs @@ -40,5 +40,19 @@ defmodule Avrogen.Avro.Types.UnionTest do assert union == test_encode_union_primitives(val) end) end + + test "union function clause error trying to encode a non-union type" do + assert_raise FunctionClauseError, fn -> + # It's a union of null, string, bool and numbers. Map isn't an union value. + # Instead of returning the value itself, it should return an error. + test_encode_union_primitives(%{}) + end + end + + test "union function clause error trying to decode a non-union type" do + # assert {:error, _} = test_decode_union_primitives(%{}) + # Note: that's not the correct behavior. The function should return an error. + assert {:ok, %{}} = test_decode_union_primitives(%{}) + end end end