From 18cdcb43301ca270400bb644eb6e4f72822ac533 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 10 Jan 2012 21:08:43 -0800 Subject: [PATCH] Acceptance tests for chef solo, fixed a bug it found. --- lib/vagrant/provisioners/chef_solo.rb | 2 +- test/acceptance/provisioning/chef_solo_test.rb | 14 +++++++++++++- .../skeletons/chef_solo_basic/README.md | 3 +++ .../cookbooks/basic/recipes/default.rb | 5 +++++ test/acceptance/support/isolated_environment.rb | 17 +++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/acceptance/skeletons/chef_solo_basic/README.md create mode 100644 test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index c77282540..ffb7d4e1b 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -113,7 +113,7 @@ module Vagrant roles_path = guest_paths(@role_folders).first data_bags_path = guest_paths(@data_bags_folders).first - setup_config("provisioners/chef_solo/solo.erb", "solo.rb", { + setup_config("provisioners/chef_solo/solo", "solo.rb", { :node_name => config.node_name, :provisioning_path => config.provisioning_path, :cookbooks_path => cookbooks_path, diff --git a/test/acceptance/provisioning/chef_solo_test.rb b/test/acceptance/provisioning/chef_solo_test.rb index 7b1f6f49f..56b504afc 100644 --- a/test/acceptance/provisioning/chef_solo_test.rb +++ b/test/acceptance/provisioning/chef_solo_test.rb @@ -4,6 +4,18 @@ describe "vagrant provisioning with chef solo" do include_context "acceptance" it "runs basic cookbooks" do - pending "Setup chef infra for tests" + # Create the chef solo basic skeleton + environment.skeleton!("chef_solo_basic") + + # Setup the basic environment + require_box("default") + assert_execute("vagrant", "box", "add", "base", box_path("default")) + + # Bring up the VM + assert_execute("vagrant", "up") + + # Check for the file it should have created + results = assert_execute("vagrant", "ssh", "-c", "cat /tmp/chef_solo_basic") + results.stdout.should == "success" end end diff --git a/test/acceptance/skeletons/chef_solo_basic/README.md b/test/acceptance/skeletons/chef_solo_basic/README.md new file mode 100644 index 000000000..4f64aa7ce --- /dev/null +++ b/test/acceptance/skeletons/chef_solo_basic/README.md @@ -0,0 +1,3 @@ +# Chef Solo Basic Skeleton + +This is a skeleton that contains a basic chef solo setup. diff --git a/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb b/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb new file mode 100644 index 000000000..5f6add780 --- /dev/null +++ b/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb @@ -0,0 +1,5 @@ +# Just create a file +file "/tmp/chef_solo_basic" do + mode 0644 + content "success" +end diff --git a/test/acceptance/support/isolated_environment.rb b/test/acceptance/support/isolated_environment.rb index 1b7b791de..bff7491df 100644 --- a/test/acceptance/support/isolated_environment.rb +++ b/test/acceptance/support/isolated_environment.rb @@ -1,3 +1,6 @@ +require "fileutils" +require "pathname" + require "log4r" require "childprocess" @@ -11,6 +14,8 @@ module Acceptance # run in. It creates a temporary directory to act as the # working directory as well as sets a custom home directory. class IsolatedEnvironment < ::IsolatedEnvironment + SKELETON_DIR = Pathname.new(File.expand_path("../../skeletons", __FILE__)) + def initialize(apps=nil, env=nil) super() @@ -25,6 +30,16 @@ module Acceptance @env["VBOX_USER_HOME"] ||= @homedir.to_s end + # Copies a skeleton into this isolated environment. This is useful + # for testing environments that require a complex setup. + # + # @param [String] name Name of the skeleton in the skeletons/ directory. + def skeleton!(name) + # Copy all the files into the home directory + source = Dir.glob(SKELETON_DIR.join(name).join("*").to_s) + FileUtils.cp_r(source, @workdir.to_s) + end + # Executes a command in the context of this isolated environment. # Any command executed will therefore see our temporary directory # as the home directory. @@ -61,6 +76,8 @@ module Acceptance super end + protected + def delete_virtual_machines # Delete all virtual machines @logger.debug("Finding all virtual machines")