Browse Source

Add a test cookbook and matching Cucumber features.

Andrea Campi 11 years ago
parent
commit
3ae422e1ae

+ 8 - 1
Gemfile

@@ -1,3 +1,10 @@
 source :rubygems
 
-gem 'test-kitchen'
+gem 'cucumber', '~> 1.2.1'
+gem 'httparty', '~> 0.8.3'
+gem 'minitest', '~> 3.0.0'
+gem 'nokogiri', '~> 1.5.0'
+
+group :kitchen  do
+  gem 'test-kitchen'
+end

+ 17 - 0
Gemfile.lock

@@ -2,6 +2,7 @@ GEM
   remote: http://rubygems.org/
   specs:
     archive-tar-minitar (0.5.2)
+    builder (3.1.3)
     bunny (0.7.9)
     chef (10.14.2)
       bunny (>= 0.6.0, < 0.8.0)
@@ -24,6 +25,12 @@ GEM
     childprocess (0.3.5)
       ffi (~> 1.0, >= 1.0.6)
     coderay (1.0.7)
+    cucumber (1.2.1)
+      builder (>= 2.1.2)
+      diff-lcs (>= 1.1.3)
+      gherkin (~> 2.11.0)
+      json (>= 1.4.6)
+    diff-lcs (1.1.3)
     erubis (2.7.0)
     ffi (1.1.5)
     foodcritic (1.6.1)
@@ -40,6 +47,9 @@ GEM
     gist (3.1.0)
     hashr (0.0.22)
     highline (1.6.15)
+    httparty (0.8.3)
+      multi_json (~> 1.0)
+      multi_xml
     i18n (0.6.1)
     ipaddress (0.8.0)
     json (1.5.4)
@@ -51,6 +61,7 @@ GEM
     log4r (1.1.10)
     method_source (0.7.1)
     mime-types (1.19)
+    minitest (3.0.1)
     mixlib-authentication (1.3.0)
       mixlib-log
     mixlib-cli (1.2.2)
@@ -58,6 +69,8 @@ GEM
     mixlib-log (1.4.1)
     mixlib-shellout (1.1.0)
     moneta (0.6.0)
+    multi_json (1.3.6)
+    multi_xml (0.5.1)
     net-scp (1.0.4)
       net-ssh (>= 1.99.1)
     net-ssh (2.2.2)
@@ -112,4 +125,8 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
+  cucumber (~> 1.2.1)
+  httparty (~> 0.8.3)
+  minitest (~> 3.0.0)
+  nokogiri (~> 1.5.0)
   test-kitchen

+ 13 - 0
test/features/basic_app.feature

@@ -0,0 +1,13 @@
+@basic_app
+Feature: Deploy a basic app
+
+In order to run my application
+As a developer
+I want to deploy a basic application
+
+  Scenario: Deploy a basic app
+    Given a new server
+    Then the "/var/www/basic_app" directory should exist
+    And the "/var/www/basic_app/shared" directory should exist
+    And the "/var/www/basic_app/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f" directory should exist
+    And "/var/www/basic_app/current" should be a symlink to "/var/www/basic_app/releases/0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"

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

@@ -0,0 +1,12 @@
+Given /^a new server$/ do
+end
+
+Then /^the "?(.+?)"? directory should exist$/ do |dir_name|
+  @dir_name = dir_name
+  assert File.directory?(dir_name), "File.directory?(#{dir_name}) = #{File.directory?(dir_name)}"
+end
+
+Then /^"?(.+?)"? should be a symlink to "?(.+?)"$/ do |link, target|
+  assert File.symlink?(link)
+  assert_equal target, File.readlink(link)
+end

+ 3 - 0
test/features/support/env.rb

@@ -0,0 +1,3 @@
+require 'minitest/spec'
+World(MiniTest::Assertions)
+MiniTest::Spec.new(nil)

+ 4 - 0
test/kitchen/Kitchenfile

@@ -0,0 +1,4 @@
+cookbook "application" do
+  configuration "basic_app"
+  run_list_extras ['application_test::setup']
+end

+ 12 - 0
test/kitchen/cookbooks/application_test/CHANGELOG.md

@@ -0,0 +1,12 @@
+# CHANGELOG for application_test
+
+This file is used to list changes made in each version of application_test.
+
+## 0.1.0:
+
+* Initial release of application_test
+
+- - - 
+Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
+
+The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.

+ 12 - 0
test/kitchen/cookbooks/application_test/README.md

@@ -0,0 +1,12 @@
+Description
+===========
+
+Requirements
+============
+
+Attributes
+==========
+
+Usage
+=====
+

+ 20 - 0
test/kitchen/cookbooks/application_test/attributes/default.rb

@@ -0,0 +1,20 @@
+#
+# Cookbook Name:: application_test
+# Attributes:: default
+#
+# 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.
+#
+
+default['application_test']['root_dir'] = '/var/www'

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

@@ -0,0 +1,28 @@
+#
+# Cookbook Name:: application_test
+# Library:: test_setup
+#
+# 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.
+#
+
+require 'fileutils'
+
+def remove_app(app_name)
+  app_dir = "#{node['application_test']['root_dir']}/#{app_name}"
+  rev_path = "/tmp/vagrant-chef-1/revision-deploys/#{app_name}"
+
+  FileUtils.rm_rf(app_dir)
+  FileUtils.rm(rev_path) if File.exists?(rev_path)
+end

+ 10 - 0
test/kitchen/cookbooks/application_test/metadata.rb

@@ -0,0 +1,10 @@
+maintainer       "ZephirWorks"
+maintainer_email "andrea.campi@zephirworks.com"
+license          "Apache 2.0"
+description      "Acceptance tests for application"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version          "0.1.0"
+
+%w{application rvm}.each do |cb|
+  depends cb
+end

+ 29 - 0
test/kitchen/cookbooks/application_test/recipes/basic_app.rb

@@ -0,0 +1,29 @@
+#
+# Cookbook Name:: application_test
+# Recipe:: basic_app
+#
+# 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 = "basic_app"
+app_dir = "#{node['application_test']['root_dir']}/#{app_name}"
+
+remove_app(app_name)
+
+application app_name do
+  repository  "https://github.com/h5bp/html5-boilerplate.git"
+  revision    "0b60046431d14b6615d53ae6d8bd0ac62ae3eb6f"  # v4.0.0 tag
+  path        app_dir
+end

+ 18 - 0
test/kitchen/cookbooks/application_test/recipes/default.rb

@@ -0,0 +1,18 @@
+#
+# Cookbook Name:: application_test
+# Recipe:: default
+#
+# 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.
+#

+ 22 - 0
test/kitchen/cookbooks/application_test/recipes/setup.rb

@@ -0,0 +1,22 @@
+case node.platform
+  when 'ubuntu'
+    %w{libxml2 libxml2-dev libxslt1-dev}.each do |pkg|
+      package pkg do
+        action :install
+      end
+    end
+  when 'centos'
+    %w{libxml2 libxml2-devel libxslt libxslt-devel}.each do |pkg|
+      package pkg do
+        action :install
+      end
+    end
+end
+
+node.set['rvm']['user_installs'] = [
+  { 'user'          => 'vagrant',
+    'default_ruby'  => 'ruby-1.9.2-p320',
+    'rubies'        => [] 
+  }
+]
+include_recipe "rvm::user"