Skip to content

Commit

Permalink
[TOOL-564] Beef up utils_test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiMed committed Mar 13, 2024
1 parent 2433bad commit f6827e6
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions test/airbrake/utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,31 @@ defmodule Airbrake.UtilsTest do
assert Utils.detuple(input) == expected
end

test "returns the original data when input is a map with no tuples" do
input = %{baz: 100, qux: 200}
test "returns detupled data when input is a map with tuples" do
input = %{baz: {1, 2}, qux: {:ok, "sucess"}}
expected = %{baz: [1, 2], qux: [:ok, "sucess"]}

assert Utils.detuple(input) == input
assert Utils.detuple(input) == expected
end

test "returns the original data when input is a list with no tuples" do
input = ["foo", "bar"]
test "returns detupled data when input is a list with tuples" do
input = ["foo", {:ok, "sucess"}]
expected = ["foo", [:ok, "sucess"]]

assert Utils.detuple(input) == input
assert Utils.detuple(input) == expected
end

test "returns a list when input is a tuple" do
input = {:ok, "something"}
test "returns a list when input is nested tuples" do
input = {:ok, {:error, "something"}}
expected = [:ok, [:error, "something"]]

assert Utils.detuple(input) == [:ok, "something"]
assert Utils.detuple(input) == expected
end

test "returns the original value when the input is anything else" do
input = "something"

assert Utils.detuple(input) == input
property "scalars are returned unchanged" do
check all scalar <- one_of(integer(), float(), string(:utf8), atom(), boolean()) do

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.14

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.12

undefined function one_of/5

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.12

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.14

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.13

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.13

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.14

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.13

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check failure on line 87 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.13

** (CompileError) test/airbrake/utils_test.exs:87: undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)
assert Utils.detuple(scalar) == scalar
end
end
end

Expand All @@ -102,22 +105,31 @@ defmodule Airbrake.UtilsTest do
assert Utils.destruct(input) == expected
end

test "returns the original data when input is a list" do
input = ["foo", "bar"]
test "returns de-structed data when input is a list containing a struct" do
input = ["foo", %Struct{baz: 100, qux: 200}]
expected = ["foo", %{baz: 100, qux: 200}]

assert Utils.destruct(input) == input
assert Utils.destruct(input) == expected
end

test "returns the original data when input is a tuple" do
input = {:ok, "success"}
test "returns the de-structed data when input is a tuple containing a struct" do
input = {:ok, %Struct{baz: 100, qux: 200}}
expected = {:ok, %{baz: 100, qux: 200}}

assert Utils.destruct(input) == input
assert Utils.destruct(input) == expected
end

test "returns a map of the original data when input is a struct" do
input = %Struct{baz: 100, qux: 200}
test "returns a map of the original data when input contains nested structs" do
input = %Struct{baz: 100, qux: %Struct{baz: 100, qux: 200}}
expected = %{baz: 100, qux: %{baz: 100, qux: 200}}

assert Utils.destruct(input) == %{baz: 100, qux: 200}
assert Utils.destruct(input) == expected
end

property "scalars are returned unchanged" do
check all scalar <- one_of(integer(), float(), string(:utf8), atom(), boolean()) do

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.14

undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.12

undefined function one_of/5

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.12

undefined function atom/0

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.14

undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.13

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 24 / Elixir 1.13

undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.14

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.14

undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.13

undefined function one_of/5 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)

Check warning on line 130 in test/airbrake/utils_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25 / Elixir 1.13

undefined function atom/0 (expected Airbrake.UtilsTest to define such a function or for it to be imported, but none are available)
assert Utils.destruct(scalar) == scalar
end
end
end
end

0 comments on commit f6827e6

Please sign in to comment.