diff --git a/.gitignore b/.gitignore index 5bcb1b1..1f81f22 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,9 @@ erl_crash.dump id3-*.tar # Rustler creates native files inside /priv. We'll ignore that. -/priv/native/* \ No newline at end of file +/priv/native/* + +native/id3/.cargo/config + +.DS_Store +priv/.DS_Store \ No newline at end of file diff --git a/priv/sample_mp3/WAKADINALI-Morio-Anzenza-Ft-Dyana-Cods.mp3 b/priv/sample_mp3/WAKADINALI-Morio-Anzenza-Ft-Dyana-Cods.mp3 new file mode 100644 index 0000000..526f4dd Binary files /dev/null and b/priv/sample_mp3/WAKADINALI-Morio-Anzenza-Ft-Dyana-Cods.mp3 differ diff --git a/test/id3v2_test.exs b/test/id3v2_test.exs index 72d0018..8fe2eed 100644 --- a/test/id3v2_test.exs +++ b/test/id3v2_test.exs @@ -1,8 +1,55 @@ defmodule ID3Test do use ExUnit.Case - doctest ID3 + # doctest ID3 + @path_to_sample_mp3 "priv/sample_mp3/WAKADINALI-Morio-Anzenza-Ft-Dyana-Cods.mp3" - test "greets the world" do - assert ID3.hello() == :world + describe "get_tag" do + test "get_tag!/1: return ID3_struct when valid mp3 path provided" do + assert %ID3.Tag{} = ID3.get_tag!(@path_to_sample_mp3) + end + + test "get_tag/1: return {:ok, ID3_struct} when valid mp3 path provided" do + assert { + :ok, + %ID3.Tag{} + } = ID3.get_tag(@path_to_sample_mp3) + end + + test "get_tag/1: return error tuple when invalid path provided" do + assert {:error, :file_open_error} = ID3.get_tag("") + end + end + + describe "write_tag" do + test "write_tag/2" do + # get file with year: nil + assert { + :ok, + %ID3.Tag{ + year: nil + } = tag + } = ID3.get_tag(@path_to_sample_mp3) + + # write tag year: 2020 + ID3.write_tag(%{tag | year: 2020}, @path_to_sample_mp3) + # assert tag year: 2020 + assert { + :ok, + %ID3.Tag{year: 2020} = tag + } = ID3.get_tag(@path_to_sample_mp3) + + on_exit(fn -> + IO.puts( + "#{__MODULE__}.on_exit/1 cleaning up test: write_tag/2 -> resetting test file to initial tag" + ) + + ID3.write_tag(%{tag | year: nil}, @path_to_sample_mp3) + + assert { + :ok, + %ID3.Tag{year: nil} + } = ID3.get_tag(@path_to_sample_mp3) + end) + end end end