defmodule GitGud.Workflows.RefTest do
@moduledoc """
The ref parsing three places used to do separately.
`github.ref_type` being absent from the runner context is what made a
release workflow take its "not a tag" branch on a tag push and report
success for publishing nothing, so the spellings here are GitHub's — a
workflow copied from its documentation compares against exactly these
strings.
"""
use ExUnit.Case, async: true
doctest GitGud.Workflows.Ref
alias GitGud.Workflows.Ref
describe "name/1" do
test "strips the ref prefix" do
assert Ref.name("refs/heads/master") == "master"
assert Ref.name("refs/tags/v0.1.0") == "v0.1.0"
end
test "keeps a slash inside the name" do
assert Ref.name("refs/heads/topic/thing") == "topic/thing"
end
test "passes anything else through rather than blanking it" do
assert Ref.name("HEAD") == "HEAD"
assert Ref.name(nil) == ""
end
end
describe "type/1" do
test "is GitHub's spelling" do
assert Ref.type("refs/heads/master") == "branch"
assert Ref.type("refs/tags/v0.1.0") == "tag"
end
test "is empty for a ref that is neither" do
assert Ref.type("refs/pull/7/head") == ""
assert Ref.type(nil) == ""
end
end
describe "context/1" do
test "names the one key the filters look at" do
assert Ref.context("refs/heads/master") == %{branch: "master"}
assert Ref.context("refs/tags/v0.1.0") == %{tag: "v0.1.0"}
end
# A context that guessed would make `branches:` and `tags:` filters
# decide on a ref that is neither; an empty one filters on nothing.
test "is empty for a ref that is neither" do
assert Ref.context("refs/pull/7/head") == %{}
assert Ref.context(nil) == %{}
end
end
end
neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
1
Log in to mark this repository.
1.8 KiB · text
History
7d9322a