Browse Source

Add a failing test for block callbacks.

Andrea Campi 11 years ago
parent
commit
9013b6a21e

+ 15 - 0
test/features/block_callbacks.feature

@@ -0,0 +1,15 @@
+@block_callbacks
+Feature: Run block callbacks
+
+In order to write my application recipe
+As a recipe developer
+I want my callbacks to be called
+
+  Scenario: Deploy a basic app
+    Given a new server
+    Then the "/var/www/block_callbacks" directory should exist
+    And the "/var/www/block_callbacks/shared" directory should exist
+    And the "/var/www/block_callbacks/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f" directory should exist
+    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"

+ 11 - 0
test/features/step_definitions/app_steps.rb

@@ -6,6 +6,11 @@ Then /^the "?(.+?)"? directory should exist$/ do |dir_name|
   assert File.directory?(dir_name), "File.directory?(#{dir_name}) = #{File.directory?(dir_name)}"
 end
 
+Then /^the "?(.+?)"? file should exist$/ do |file_name|
+  @file_name = file_name
+  assert File.file?(file_name)
+end
+
 Then /^it should be owned by (.+?) with group (.+?)$/ do |owner, group|
   # TODO
 end
@@ -14,3 +19,9 @@ Then /^"?(.+?)"? should be a symlink to "?(.+?)"$/ do |link, target|
   assert File.symlink?(link)
   assert_equal target, File.readlink(link)
 end
+
+Then /^it should contain a line matching "(.+?)"$/ do |regexp|
+  content = File.open(@file_name).read
+  re = Regexp.new("^#{regexp}$")
+  assert content =~ re
+end

+ 1 - 0
test/kitchen/Kitchenfile

@@ -1,5 +1,6 @@
 cookbook "application" do
   configuration "basic_app"
+  configuration "block_callbacks"
   lint false                  # XXX
   run_list_extras ['application_test::setup']
 end

+ 9 - 0
test/kitchen/cookbooks/application_test/libraries/test_setup.rb

@@ -26,3 +26,12 @@ def remove_app(app_name)
   FileUtils.rm_rf(app_dir)
   FileUtils.rm(rev_path) if File.exists?(rev_path)
 end
+
+def test_results(app_name)
+  tmp_dir = "/tmp/#{app_name}"
+
+  FileUtils.rm_rf(tmp_dir)
+  FileUtils.mkdir_p(tmp_dir)
+
+  tmp_dir
+end

+ 43 - 0
test/kitchen/cookbooks/application_test/recipes/block_callbacks.rb

@@ -0,0 +1,43 @@
+#
+# Cookbook Name:: application_test
+# Recipe:: block_callbacks
+#
+# Copyright 2012, ZephirWorks
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+app_name = "block_callbacks"
+app_dir = "#{node['application_test']['root_dir']}/#{app_name}"
+
+remove_app(app_name)
+tmp_dir = test_results(app_name)
+
+application app_name do
+  repository  "https://github.com/h5bp/html5-boilerplate.git"
+  revision    "0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"  # v4.0.0 tag
+  path        app_dir
+  owner       node['application_test']['owner']
+  group       node['application_test']['group']
+
+  before_deploy do
+    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)
+    end
+  end
+end

+ 2 - 0
test/kitchen/cookbooks/application_test/templates/default/hooks.erb

@@ -0,0 +1,2 @@
+release_path <%= @release_path %>
+shared_path <%= @shared_path %>