Skip to content

Commit 7300561

Browse files
committed
Add tests for custom_hook
1 parent 354a0fb commit 7300561

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

spec/defines/custom_hook_spec.rb

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
require 'spec_helper'
2+
3+
describe 'gitlab::custom_hook' do
4+
let(:title) { 'test-hook' }
5+
6+
let(:pre_condition) do
7+
<<-MANIFEST
8+
class { 'gitlab':
9+
repository_configuration => {},
10+
}
11+
MANIFEST
12+
end
13+
14+
['post-receive', 'pre-receive', 'update'].each do |type|
15+
context "with type => #{type} and source" do
16+
let(:source) { 'puppet:///modules/my_module/post-receive' }
17+
let(:params) do
18+
{
19+
type: type,
20+
custom_hooks_dir: '/custom/hooks/dir',
21+
source: source,
22+
namespace: 'foo',
23+
project: 'bar'
24+
}
25+
end
26+
27+
it { is_expected.to compile }
28+
29+
it do
30+
is_expected.to contain_file("/custom/hooks/dir/foo/bar.git/custom_hooks/#{type}.d").
31+
with_ensure('directory')
32+
end
33+
34+
it do
35+
is_expected.to contain_file("/custom/hooks/dir/foo/bar.git/custom_hooks/#{type}.d/#{title}").
36+
with_ensure('file').
37+
with_source(source)
38+
end
39+
end
40+
41+
context "with type => #{type} and content" do
42+
let(:content) { "#!/usr/bin/env bash\ntest 0" }
43+
let(:params) do
44+
{
45+
type: type,
46+
custom_hooks_dir: '/custom/hooks/dir',
47+
content: content,
48+
namespace: 'foo',
49+
project: 'bar'
50+
}
51+
end
52+
53+
it { is_expected.to compile }
54+
55+
it do
56+
is_expected.to contain_file("/custom/hooks/dir/foo/bar.git/custom_hooks/#{type}.d").
57+
with_ensure('directory')
58+
end
59+
60+
it do
61+
is_expected.to contain_file("/custom/hooks/dir/foo/bar.git/custom_hooks/#{type}.d/#{title}").
62+
with_ensure('file').
63+
with_content(content)
64+
end
65+
end
66+
67+
context "with type => #{type} and project hash" do
68+
let(:content) { "#!/usr/bin/env bash\ntest 0" }
69+
let(:params) do
70+
{
71+
type: type,
72+
custom_hooks_dir: '/custom/hooks/dir',
73+
content: content,
74+
hashed_storage: true,
75+
project: '6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d'
76+
}
77+
end
78+
79+
it { is_expected.to compile }
80+
81+
it do
82+
is_expected.to contain_file("/custom/hooks/dir/@hashed/6e/40/6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d.git/custom_hooks/#{type}.d").
83+
with_ensure('directory')
84+
end
85+
86+
it do
87+
is_expected.to contain_file("/custom/hooks/dir/@hashed/6e/40/6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d.git/custom_hooks/#{type}.d/#{title}").
88+
with_ensure('file').
89+
with_content(content)
90+
end
91+
end
92+
93+
context "with type => #{type} and project id" do
94+
let(:content) { "#!/usr/bin/env bash\ntest 0" }
95+
let(:params) do
96+
{
97+
type: type,
98+
custom_hooks_dir: '/custom/hooks/dir',
99+
content: content,
100+
hashed_storage: true,
101+
project: 93
102+
}
103+
end
104+
105+
it { is_expected.to compile }
106+
107+
it do
108+
is_expected.to contain_file("/custom/hooks/dir/@hashed/6e/40/6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d.git/custom_hooks/#{type}.d").
109+
with_ensure('directory')
110+
end
111+
112+
it do
113+
is_expected.to contain_file("/custom/hooks/dir/@hashed/6e/40/6e4001871c0cf27c7634ef1dc478408f642410fd3a444e2a88e301f5c4a35a4d.git/custom_hooks/#{type}.d/#{title}").
114+
with_ensure('file').
115+
with_content(content)
116+
end
117+
end
118+
end
119+
end

0 commit comments

Comments
 (0)