Browse Source

Test all hooks.

Andrea Campi 11 years ago
parent
commit
6ac9078f70

+ 12 - 0
test/features/block_callbacks.feature

@@ -13,3 +13,15 @@ I want my callbacks to be called
     And the "/tmp/block_callbacks/before_deploy" file should exist
     And it should contain a line matching "release_path /var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"
     And it should contain a line matching "shared_path /var/www/block_callbacks/shared"
+    And the "/tmp/block_callbacks/before_migrate" file should exist
+    And it should contain a line matching "release_path /var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"
+    And it should contain a line matching "shared_path /var/www/block_callbacks/shared"
+    And the "/tmp/block_callbacks/before_symlink" file should exist
+    And it should contain a line matching "release_path /var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"
+    And it should contain a line matching "shared_path /var/www/block_callbacks/shared"
+    And the "/tmp/block_callbacks/before_restart" file should exist
+    And it should contain a line matching "release_path /var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"
+    And it should contain a line matching "shared_path /var/www/block_callbacks/shared"
+    And the "/tmp/block_callbacks/after_restart" file should exist
+    And it should contain a line matching "release_path /var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"
+    And it should contain a line matching "shared_path /var/www/block_callbacks/shared"

+ 12 - 7
test/kitchen/cookbooks/application_test/recipes/block_callbacks.rb

@@ -30,14 +30,19 @@ application app_name do
   owner       node['application_test']['owner']
   group       node['application_test']['group']
 
-  before_deploy do
-    resource = @new_resource
+  #
+  # All these hooks should be invoked with the same context
+  #
+  %w[before_deploy before_migrate before_symlink before_restart after_restart].each do |hook_name|
+    send(hook_name) do # invoke the hook by name
+      resource = @new_resource
 
-    template "#{tmp_dir}/before_deploy" do
-      source "hooks.erb"
-      mode 0644
-      variables(:release_path => resource.release_path,
-                :shared_path  => resource.shared_path)
+      template "#{tmp_dir}/#{hook_name}" do
+        source "hooks.erb"
+        mode 0644
+        variables(:release_path => resource.release_path,
+                  :shared_path  => resource.shared_path)
+      end
     end
   end
 end