Skip to content

Commit 19b7970

Browse files
committed
Add first tests to install module
1 parent 7d72f3a commit 19b7970

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
defmodule Mix.Tasks.InstallTest do
2+
@moduledoc false
3+
4+
use ExUnit.Case, async: false
5+
use GitHooks.TestSupport.ConfigCase
6+
7+
alias Mix.Tasks.GitHooks.Install
8+
alias GitHooks.Git.Path, as: GitPath
9+
10+
@tag capture_log: true
11+
12+
describe "run/1" do
13+
test "replaces the hook template with config values" do
14+
put_git_hook_config(
15+
[:pre_commit, :pre_push],
16+
tasks: {:cmd, "check"}
17+
)
18+
19+
hooks_file = Install.run(["--dry-run", "--quiet"])
20+
21+
assert hooks_file == [
22+
pre_commit: expect_hook_template("pre_commit"),
23+
pre_push: expect_hook_template("pre_push")
24+
]
25+
end
26+
end
27+
28+
#
29+
# Private functions
30+
#
31+
32+
defp expect_hook_template(git_hook) do
33+
app_path = GitPath.resolve_app_path()
34+
35+
~s(#!/bin/sh
36+
37+
[ "#{app_path}" != "" ] && cd #{app_path}
38+
39+
mix git_hooks.run #{git_hook} "$@"
40+
[ $? -ne 0 ] && exit 1
41+
exit 0
42+
)
43+
end
44+
end

0 commit comments

Comments
 (0)