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

[PUWEN-1504]: avrogen: optional maps #6

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/avrogen/avro/types/union.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions test/avro/types/union_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading