Commit ebd822e937e759294c71374a29c405259f7940c4
1 parent
098f1c0d
Exists in
master
and in
22 other branches
plugin-tests-task: refactor to allow independent plugin test run
Making every plugin run its tests with independently, with only its migrations and only it enabled.
Showing
5 changed files
with
88 additions
and
52 deletions
Show diff stats
lib/noosfero.rb
lib/tasks/plugins_tests.rake
1 | -all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] | |
1 | +@all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] | |
2 | +@all_tasks = [:units, :functionals, :integration, :cucumber, :selenium] | |
3 | + | |
2 | 4 | def enabled_plugins |
3 | 5 | Dir.glob('config/plugins/*').map { |f| File.basename(f) } - ['README'] |
4 | 6 | end |
5 | -disabled_plugins = all_plugins - enabled_plugins | |
7 | + | |
8 | +@original_enabled_plugins = enabled_plugins | |
9 | + | |
10 | +def disabled_plugins | |
11 | + @all_plugins - enabled_plugins | |
12 | +end | |
13 | + | |
14 | +def enable_plugins(plugins = nil) | |
15 | + if plugins == '*' || plugins.nil? | |
16 | + sh './script/noosfero-plugins', '-q', 'enableall' | |
17 | + else | |
18 | + plugins = Array(plugins) | |
19 | + sh './script/noosfero-plugins', '-q', 'enable', *plugins | |
20 | + end | |
21 | +end | |
22 | + | |
23 | +def disable_plugins(plugins = nil) | |
24 | + if plugins == '*' || plugins.nil? | |
25 | + sh './script/noosfero-plugins', '-q', 'disableall' | |
26 | + else | |
27 | + plugins = Array(plugins) | |
28 | + sh './script/noosfero-plugins', '-q', 'disable', *plugins | |
29 | + end | |
30 | +end | |
31 | + | |
32 | +def rollback_plugins_state | |
33 | + puts | |
34 | + puts "==> Rolling back plugins to their original states..." | |
35 | + disable_plugins | |
36 | + enable_plugins(@original_enabled_plugins) | |
37 | +end | |
6 | 38 | |
7 | 39 | task 'db:test:plugins:prepare' do |
8 | 40 | if Dir.glob('config/plugins/*/db/migrate/*.rb').empty? |
9 | 41 | puts "I: skipping database setup, enabled plugins have no migrations" |
10 | 42 | else |
11 | - Rake::Task['db:test:prepare'].invoke | |
43 | + Rake::Task['db:test:prepare'].execute | |
12 | 44 | sh 'rake db:migrate RAILS_ENV=test SCHEMA=/dev/null' |
13 | 45 | end |
14 | 46 | end |
... | ... | @@ -101,72 +133,74 @@ def run_tests(name, plugins, run=:individually) |
101 | 133 | end |
102 | 134 | end |
103 | 135 | |
104 | -def plugin_test_task(name, plugin, run=:individually) | |
105 | - desc "Run #{name} tests for #{plugin_name(plugin)}" | |
106 | - task name => 'db:test:plugins:prepare' do |t| | |
107 | - if plugin_enabled?(plugin) | |
108 | - run_tests(name, plugin, run) | |
109 | - else | |
110 | - plugin_disabled_warning(plugin) | |
136 | +def test_sequence(plugins, tasks) | |
137 | + failed = {} | |
138 | + disable_plugins | |
139 | + plugins = @all_plugins if plugins == '*' | |
140 | + plugins = Array(plugins) | |
141 | + tasks = Array(tasks) | |
142 | + plugins.each do |plugin| | |
143 | + failed[plugin] = [] | |
144 | + enable_plugins(plugin) | |
145 | + next if !plugin_enabled?(plugin) | |
146 | + begin | |
147 | + Rake::Task['db:test:plugins:prepare' ].execute | |
148 | + rescue Exception => ex | |
149 | + failed[plugin] << :migration | |
111 | 150 | end |
112 | - end | |
113 | -end | |
114 | - | |
115 | -def test_sequence_task(name, plugin, *tasks) | |
116 | - desc "Run all tests for #{plugin_name(plugin)}" | |
117 | - task name do | |
118 | - failed = [] | |
119 | 151 | tasks.each do |task| |
120 | 152 | begin |
121 | - Rake::Task['test:noosfero_plugins:' + task.to_s].invoke | |
153 | + run_tests(task, plugin) | |
122 | 154 | rescue Exception => ex |
123 | 155 | puts ex |
124 | - failed << task | |
156 | + failed[plugin] << task | |
125 | 157 | end |
126 | 158 | end |
127 | - unless failed.empty? | |
128 | - fail 'Tests failed: ' + failed.join(', ') | |
159 | + disable_plugins(plugin) | |
160 | + end | |
161 | + fail_flag = false | |
162 | + failed.each do |plugin, tasks| | |
163 | + unless tasks.empty? | |
164 | + puts "Tests failed on #{plugin} plugin: #{tasks.join(', ')}" | |
165 | + fail_flag = true | |
129 | 166 | end |
130 | 167 | end |
168 | + rollback_plugins_state | |
169 | + fail 'There are broken tests to be fixed!' if fail_flag | |
170 | +end | |
171 | + | |
172 | +def plugin_test_task(plugin, task, run=:individually) | |
173 | + desc "Run #{task} tests for #{plugin_name(plugin)}" | |
174 | + task task do | |
175 | + test_sequence(plugin, task) | |
176 | + end | |
131 | 177 | end |
132 | 178 | |
133 | 179 | namespace :test do |
134 | 180 | namespace :noosfero_plugins do |
135 | - all_plugins.each do |plugin| | |
181 | + @all_plugins.each do |plugin| | |
136 | 182 | namespace plugin do |
137 | - plugin_test_task :units, plugin | |
138 | - plugin_test_task :functionals, plugin | |
139 | - plugin_test_task :integration, plugin | |
140 | - plugin_test_task :cucumber, plugin | |
141 | - plugin_test_task :selenium, plugin | |
183 | + @all_tasks.each do |taskname| | |
184 | + plugin_test_task plugin, taskname | |
185 | + end | |
142 | 186 | end |
143 | 187 | |
144 | - test_sequence_task(plugin, plugin, "#{plugin}:units", "#{plugin}:functionals", "#{plugin}:integration", "#{plugin}:cucumber", "#{plugin}:selenium") | |
145 | - end | |
146 | - | |
147 | - [:units, :functionals, :integration].each do |taskname| | |
148 | - task taskname => 'db:test:plugins:prepare' do |t| | |
149 | - run_tests taskname, enabled_plugins | |
188 | + desc "Run all tests for #{plugin_name(plugin)}" | |
189 | + task plugin do | |
190 | + test_sequence([plugin], @all_tasks) | |
150 | 191 | end |
151 | 192 | end |
152 | 193 | |
153 | - task :cucumber => 'db:test:plugins:prepare' do |t| | |
154 | - run_tests :cucumber, enabled_plugins | |
155 | - end | |
156 | - | |
157 | - task :selenium => 'db:test:plugins:prepare' do |t| | |
158 | - run_tests :selenium, enabled_plugins | |
159 | - end | |
160 | - | |
161 | - task :temp_enable_all_plugins do | |
162 | - sh './script/noosfero-plugins', 'enableall' | |
163 | - end | |
164 | - | |
165 | - task :rollback_enable_all_plugins do | |
166 | - sh './script/noosfero-plugins', 'disable', *disabled_plugins | |
194 | + @all_tasks.each do |taskname| | |
195 | + desc "Run #{taskname} tests for all plugins" | |
196 | + task taskname do | |
197 | + test_sequence(@all_plugins, taskname) | |
198 | + end | |
167 | 199 | end |
168 | 200 | end |
169 | 201 | |
170 | - test_sequence_task(:noosfero_plugins, '*', :temp_enable_all_plugins, :units, :functionals, :integration, :cucumber, :selenium, :rollback_enable_all_plugins) | |
171 | - | |
202 | + desc "Run all tests for all plugins" | |
203 | + task :noosfero_plugins do | |
204 | + test_sequence(@all_plugins, @all_tasks) | |
205 | + end | |
172 | 206 | end | ... | ... |
plugins/ldap/install.rb
... | ... | @@ -4,7 +4,7 @@ rescue Gem::LoadError => exception |
4 | 4 | system "gem install --user-install net-ldap -v 0.3.1" |
5 | 5 | end |
6 | 6 | |
7 | -puts "\nWARNING: This plugin is not setting up a ldap test server automatically. | |
7 | +puts "WARNING: This plugin is not setting up a ldap test server automatically. | |
8 | 8 | Some tests may not be running. If you want to fully test this plugin, please |
9 | 9 | setup the ldap test server and make the proper configurations on |
10 | 10 | fixtures/ldap.yml.\n\n" | ... | ... |
plugins/ldap/test/test_helper.rb
... | ... | @@ -20,4 +20,4 @@ def ldap_configured? |
20 | 20 | end |
21 | 21 | end |
22 | 22 | |
23 | -LDAP_SERVER_ERROR_MESSAGE = "\n\nWARNING: LDAP test server is not configured properly. Please see the file fixtures/ldap.yml on ldap plugin\n\n" | |
23 | +LDAP_SERVER_ERROR_MESSAGE = "\nWARNING: LDAP test server is not configured properly. Please see the file fixtures/ldap.yml on ldap plugin\n\n" | ... | ... |
script/noosfero-plugins
... | ... | @@ -108,8 +108,10 @@ _enable(){ |
108 | 108 | needs_migrate=true |
109 | 109 | elif [ "$installation_ok" = false ]; then |
110 | 110 | echo "W: failed to install $plugin; not enabling" |
111 | + echo | |
111 | 112 | elif [ "$dependencies_ok" = false ]; then |
112 | 113 | echo "W: failed to load dependencies for $plugin; not enabling" |
114 | + echo | |
113 | 115 | fi |
114 | 116 | fi |
115 | 117 | } |
... | ... | @@ -227,6 +229,7 @@ esac |
227 | 229 | |
228 | 230 | if [ "$needs_migrate" = 'true' ] && [ "$quiet" = 'false' ]; then |
229 | 231 | cat <<-EOF |
232 | + | |
230 | 233 | ==================================================================== |
231 | 234 | To finish the activation of the plugins you have just enabled, you |
232 | 235 | need to restart Noosfero. | ... | ... |