Page MenuHomePhorge

No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/.woodpecker/unit-testing.yaml b/.woodpecker/unit-testing.yaml
index 2d3ae27..8d2628f 100644
--- a/.woodpecker/unit-testing.yaml
+++ b/.woodpecker/unit-testing.yaml
@@ -1,31 +1,32 @@
when:
- event: pull_request
path: [ "**/*.ex", "**/*.exs", "mix.lock", "src/**", "Makefile", ".woodpecker/**" ]
- event: push
branch: ${CI_REPO_DEFAULT_BRANCH}
path: [ "**/*.ex", "**/*.exs", "mix.lock", "src/**", "Makefile", ".woodpecker/**" ]
depends_on:
- lint
labels:
platform: linux/amd64
variables:
script_file_entrypoint: &script_file_entrypoint
- /bin/sh
- -c
- 'printf "%s" "$CI_SCRIPT" | base64 -d > /tmp/ci-script.sh && /bin/sh -xe /tmp/ci-script.sh'
steps:
unit-testing:
image: elixir:1.17-alpine
entrypoint: *script_file_entrypoint
environment:
MIX_ENV: test
commands:
- - apk add --no-cache build-base file-dev git
+ - apk add --no-cache build-base file file-dev git
+ - rm -f priv/libmagic_port _build/test/lib/majic/priv/libmagic_port
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix test --trace --preload-modules
diff --git a/test/majic/majic_test.exs b/test/majic/majic_test.exs
index 42efc59..7e2aab8 100644
--- a/test/majic/majic_test.exs
+++ b/test/majic/majic_test.exs
@@ -1,107 +1,79 @@
defmodule MajicTest do
use Majic.MagicCase
alias Majic.Result
doctest Majic
@iterations 100
test "Makefile is text file" do
{:ok, pid} = Majic.Server.start_link([])
path = absolute_path("Makefile")
assert {:ok, %{mime_type: "text/x-makefile"}} = Majic.Server.perform(pid, path)
end
test "With Majic.perform" do
{:ok, pid} = Majic.Server.start_link([])
path = absolute_path("Makefile")
assert {:ok, %{mime_type: "text/x-makefile"}} = Majic.perform(path, server: pid)
end
@tag external: true
test "Load test local files" do
{:ok, pid} = Majic.Server.start_link([])
files_stream()
|> Stream.cycle()
|> Stream.take(@iterations)
|> Stream.map(&assert {:ok, %Result{}} = Majic.Server.perform(pid, &1))
|> Enum.all?()
|> assert
end
test "Non-existent file" do
{:ok, pid} = Majic.Server.start_link([])
path = missing_filename()
assert_no_file(Majic.Server.perform(pid, path))
end
test "Bytes" do
{:ok, pid} = Majic.Server.start_link([])
bytes = File.read!("test/fixtures/cat.webp")
assert {:ok, _} = Majic.Server.perform(pid, {:bytes, bytes})
end
test "Named process" do
{:ok, pid} = Majic.Server.start_link(name: :gen_magic)
path = absolute_path("Makefile")
assert {:ok, %{cycles: 0}} = Majic.Server.status(:gen_magic)
assert {:ok, %{cycles: 0}} = Majic.Server.status(pid)
assert {:ok, %Result{} = result} = Majic.Server.perform(:gen_magic, path)
assert {:ok, %{cycles: 1}} = Majic.Server.status(:gen_magic)
assert {:ok, %{cycles: 1}} = Majic.Server.status(pid)
assert "text/x-makefile" = result.mime_type
end
describe "custom database" do
setup do
- database = compile_magic_db(absolute_path("test/elixir"))
- on_exit(fn -> File.rm(database) end)
+ database = absolute_path("test/elixir")
[database: database]
end
- defp compile_magic_db(source) do
- target =
- Path.join(Path.dirname(source), Path.basename(source, Path.extname(source)) <> ".mgc")
-
- file_cmd = find_file_cmd()
-
- case System.cmd(file_cmd, ["-C", "-m", source],
- cd: Path.dirname(source),
- stderr_to_stdout: true
- ) do
- {_, 0} -> :ok
- {output, _} -> raise "file -C failed: #{output}"
- end
-
- target
- end
-
- defp find_file_cmd do
- candidates = [
- "/opt/homebrew/opt/file-formula/bin/file",
- "/usr/local/opt/file-formula/bin/file",
- "file"
- ]
-
- Enum.find(candidates, &File.exists?/1) || "file"
- end
-
test "recognises Elixir files", %{database: database} do
{:ok, pid} = Majic.Server.start_link(database_patterns: [database])
path = absolute_path("mix.exs")
assert {:ok, %Result{} = result} = Majic.Server.perform(pid, path)
assert "text/x-elixir" = result.mime_type
assert "us-ascii" = result.encoding
assert "Elixir module source text" = result.content
end
test "recognises Elixir files after a reload", %{database: database} do
{:ok, pid} = Majic.Server.start_link([])
path = absolute_path("mix.exs")
{:ok, %Result{mime_type: mime}} = Majic.Server.perform(pid, path)
refute mime == "text/x-elixir"
:ok = Majic.Server.reload(pid, [database])
assert {:ok, %Result{mime_type: "text/x-elixir"}} = Majic.Server.perform(pid, path)
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sat, Aug 8, 8:08 AM (17 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1722993
Default Alt Text
(4 KB)

Event Timeline