Skip to content

Commit 400ba63

Browse files
committed
Add unit testing for commit with option no-verify
Signed-off-by: Agora Security <github@agora-security.com>
1 parent a5e7acc commit 400ba63

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/units/test_lib.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ def test_commit_with_date
4444
assert_equal("Scott Chacon <schacon@gmail.com> #{author_date.strftime("%s %z")}", data['author'])
4545
end
4646

47+
def test_commit_with_no_verify
48+
# Backup current pre-commit hook
49+
pre_commit_path = "#{@wdir}/.git/hooks/pre-commit"
50+
pre_commit_path_bak = "#{pre_commit_path}-bak"
51+
move_file(pre_commit_path, pre_commit_path_bak)
52+
53+
# Adds a pre-commit file that should throw an error
54+
create_file(pre_commit_path, 'echo Pre-commit file. Shoud not execute; exit 1') # Error when executed
55+
File.chmod(0111, pre_commit_path)
56+
57+
create_file("#{@wdir}/test_file_2", 'content test_file_2')
58+
@lib.add('test_file_2')
59+
60+
# Error raised because of pre-commit hook and no use of no_verify option
61+
assert_raise Git::GitExecuteError do
62+
@lib.commit('commit without no verify and pre-commit file')
63+
end
64+
65+
# Error is not raised when no_verify is passed
66+
assert_nothing_raised do
67+
@lib.commit('commit with no verify and pre-commit file', no_verify: true )
68+
end
69+
70+
# Restore pre-commit hook
71+
move_file(pre_commit_path_bak, pre_commit_path)
72+
73+
# Verify the commit was created
74+
data = @lib.commit_data('HEAD')
75+
assert_equal("commit with no verify and pre-commit file\n", data['message'])
76+
end
77+
4778
def test_checkout
4879
assert(@lib.checkout('test_checkout_b',{:new_branch=>true}))
4980
assert(@lib.checkout('master'))

0 commit comments

Comments
 (0)