mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 23:50:59 +00:00
Test bad inputs
This commit is contained in:
parent
816eb78064
commit
803f0b52cc
2 changed files with 20 additions and 4 deletions
|
@ -36,11 +36,19 @@ defmodule LiveBeats.MP3Stat do
|
|||
def parse(path) do
|
||||
{tag_info, rest} = parse_tag(File.read!(path))
|
||||
duration = parse_frame(rest, 0, 0, 0)
|
||||
title = Enum.at(tag_info["TIT2"] || [], 0)
|
||||
artist = Enum.at(tag_info["TPE1"] || [], 0)
|
||||
|
||||
{:ok,
|
||||
%MP3Stat{duration: round(duration), path: path, tags: tag_info, title: title, artist: artist}}
|
||||
case duration do
|
||||
duration when is_float(duration) and duration > 0 ->
|
||||
title = Enum.at(tag_info["TIT2"] || [], 0)
|
||||
artist = Enum.at(tag_info["TPE1"] || [], 0)
|
||||
seconds = round(duration)
|
||||
|
||||
{:ok,
|
||||
%MP3Stat{duration: seconds, path: path, tags: tag_info, title: title, artist: artist}}
|
||||
|
||||
_other ->
|
||||
{:error, :bad_file}
|
||||
end
|
||||
rescue
|
||||
_ -> {:error, :bad_file}
|
||||
end
|
||||
|
|
|
@ -9,4 +9,12 @@ defmodule LiveBeats.MP3StatTest do
|
|||
assert stat.title == "Silence"
|
||||
assert stat.artist == "Anon"
|
||||
end
|
||||
|
||||
test "parse/1 with invalid mp3" do
|
||||
assert {:error, :bad_file} = MP3Stat.parse("mix.exs")
|
||||
end
|
||||
|
||||
test "parse/1 with missing file" do
|
||||
assert {:error, :bad_file} = MP3Stat.parse("lsfjslkfjslkfjs")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue