fp/apps/bright/test/bright/b2_test.exs
CJ_Clippy aa75c224fc
Some checks failed
ci / build (push) Failing after 23m29s
ci / Tests & Checks (push) Failing after 3m32s
move services/bright to apps/bright
2025-02-10 08:16:50 -08:00

68 lines
1.9 KiB
Elixir

defmodule Bright.B2Test do
use Bright.DataCase
@cdn_url Application.get_env(:bright, :public_s3_endpoint)
describe "B2" do
alias Bright.B2
alias Bright.Cache
import Bright.StreamsFixtures
@tag :acceptance
test "put/1" do
local_file = Path.absname("test/fixtures/SampleVideo_1280x720_1mb.mp4")
{:ok, %{key: key, cdn_url: cdn_url}} = B2.put(local_file)
assert key === "SampleVideo_1280x720_1mb.mp4"
end
@tag :acceptance
test "put/2" do
local_file = Path.absname("test/fixtures/SampleVideo_1280x720_1mb.mp4")
basename = Cache.generate_basename(local_file)
object_key = "test/#{basename}"
{:ok, %{key: key, cdn_url: cdn_url}} = B2.put(local_file, object_key)
assert Regex.match?(~r/SampleVideo/, key)
end
@tag :integration
test "get/1 with %Vod{}" do
stream = stream_fixture()
vod =
vod_fixture(%{
stream_id: stream.id,
s3_cdn_url: "https://futureporn-b2.b-cdn.net/test-fixture.ts"
})
{:ok, filename} = B2.get(vod)
assert :ok
assert Regex.match?(~r/\.cache\/futureporn.*\.ts/, filename)
end
@tag :acceptance
test "get/2" do
local_file = "/tmp/SampleVideo_1280x720_1mb.mp4"
File.rm(local_file)
{:ok, filename} = B2.get("test/SampleVideo_1280x720_1mb.mp4", local_file)
assert File.exists?(local_file)
assert filename === local_file
{:ok, stat} = File.stat(local_file)
assert stat.size > 0, "File is empty"
File.rm!(local_file)
end
@tag :integration
test "generate_cdn_url/1" do
assert Regex.match?(~r"https:\/\/", @cdn_url),
":public_s3_endpoint was missing from `:bright` app config, which is a requirement for this test."
object_key = "test/SampleVideo_1280x720_1mb.mp4"
cdn_url = B2.generate_cdn_url(object_key)
assert cdn_url === "#{@cdn_url}/#{object_key}"
end
end
end