From dbfce21e05fc3a04cf3df4f1f1b06fb85a5b7897 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 13:19:15 -0800 Subject: [PATCH 1/6] Start acceptance test config stuff --- .gitignore | 1 + Gemfile | 2 ++ tasks/test.rake | 1 + test/acceptance/base.rb | 1 + vagrant-spec.config.example.rb | 4 ++++ 5 files changed, 9 insertions(+) create mode 100644 test/acceptance/base.rb create mode 100644 vagrant-spec.config.example.rb diff --git a/.gitignore b/.gitignore index 56ad3f2b5..85c6ab03b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ acceptance_config.yml boxes/* /Vagrantfile /.vagrant +/vagrant-spec.config.rb # Bundler/Rubygems *.gem diff --git a/Gemfile b/Gemfile index c80ee3697..309e871f0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source "http://rubygems.org" gemspec + +gem 'vagrant-spec', path: "../vagrant-spec" diff --git a/tasks/test.rake b/tasks/test.rake index e0f7598dc..da984db0d 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -13,6 +13,7 @@ namespace :test do end RSpec::Core::RakeTask.new(:acceptance) do |t| + $: << File.expand_path("../test/acceptance", __FILE__) t.pattern = "test/acceptance/**/*_test.rb" end end diff --git a/test/acceptance/base.rb b/test/acceptance/base.rb new file mode 100644 index 000000000..3d4f00396 --- /dev/null +++ b/test/acceptance/base.rb @@ -0,0 +1 @@ +require "vagrant-testlib/acceptance" diff --git a/vagrant-spec.config.example.rb b/vagrant-spec.config.example.rb new file mode 100644 index 000000000..24c42e2df --- /dev/null +++ b/vagrant-spec.config.example.rb @@ -0,0 +1,4 @@ +Vagrant::Spec::Acceptance.configure do |c| + c.provider "virtualbox", + box_basic: "/Users/mitchellh/Downloads/package.box" +end From 0d02ada43be78911aa27fc5f1115d13f114ad12b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 13:39:23 -0800 Subject: [PATCH 2/6] providers/virtualbox: only clear shared folders if we have a VM --- plugins/providers/virtualbox/synced_folder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 52d642a05..3013b0d49 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -62,7 +62,7 @@ module VagrantPlugins end def cleanup(machine) - driver(machine).clear_shared_folders + driver(machine).clear_shared_folders if machine.id && machine.id != "" end protected From 5a0fdec789b9b2e3505c4e1453d96161fd1ece84 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 13:39:33 -0800 Subject: [PATCH 3/6] test/acceptance: set the VBOX_USER_HOME --- test/acceptance/base.rb | 3 ++- test/acceptance/shared/context_virtualbox.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/shared/context_virtualbox.rb diff --git a/test/acceptance/base.rb b/test/acceptance/base.rb index 3d4f00396..ae5d4ff1b 100644 --- a/test/acceptance/base.rb +++ b/test/acceptance/base.rb @@ -1 +1,2 @@ -require "vagrant-testlib/acceptance" +require "vagrant-spec/acceptance" +require_relative "shared/context_virtualbox" diff --git a/test/acceptance/shared/context_virtualbox.rb b/test/acceptance/shared/context_virtualbox.rb new file mode 100644 index 000000000..68c194aa3 --- /dev/null +++ b/test/acceptance/shared/context_virtualbox.rb @@ -0,0 +1,5 @@ +shared_context "provider/virtualbox" do + let(:extra_env) {{ + "VBOX_USER_HOME" => "{{homedir}}", + }} +end From fd622511578ca277c680ecef7fca8851bb2149d0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 14:24:10 -0800 Subject: [PATCH 4/6] update rake tasks for acceptance testing --- tasks/acceptance.rake | 119 +++++------------------------------------- tasks/test.rake | 5 -- 2 files changed, 14 insertions(+), 110 deletions(-) diff --git a/tasks/acceptance.rake b/tasks/acceptance.rake index 2175bb0d3..813ff86d8 100644 --- a/tasks/acceptance.rake +++ b/tasks/acceptance.rake @@ -1,113 +1,22 @@ -require 'digest/sha1' -require 'net/http' -require 'pathname' -require 'uri' -require 'yaml' - -require 'childprocess' - -require 'vagrant/util/file_checksum' - namespace :acceptance do - desc "Downloads the boxes required for running the acceptance tests." - task :boxes, :directory do |t, args| - # Create the directory where the boxes will be downloaded - box_dir = Pathname.new(args[:directory] || File.expand_path("../../boxes", __FILE__)) - box_dir.mkpath - puts "Boxes will be placed in: #{box_dir}" - - # Load the required boxes - boxes = YAML.load_file(File.expand_path("../../test/config/acceptance_boxes.yml", __FILE__)) - - boxes.each do |box| - puts "Box: #{box["name"]}" - box_file = box_dir.join("#{box["name"]}.box") - checksum = FileChecksum.new(box_file, Digest::SHA1) - - # If the box exists, we need to check the checksum and determine if we need - # to redownload the file. - if box_file.exist? - print "Box exists, checking SHA1 sum... " - if checksum.checksum == box["checksum"] - print "OK\n" - next - else - print "FAIL\n" - end - end - - # Download the file. Note that this has no error checking and just uses - # pure net/http. There could be a better way. - puts "Downloading: #{box["url"]}" - destination = box_file.open("wb") - uri = URI.parse(box["url"]) - Net::HTTP.new(uri.host, uri.port).start do |http| - http.request_get(uri.request_uri) do |response| - total = response.content_length - progress = 0 - count = 0 - - response.read_body do |segment| - # Really elementary progress meter - progress += segment.length - count += 1 - puts "Progress: #{(progress.to_f / total.to_f) * 100}%" if count % 300 == 0 - - # Write out to the destination file - destination.write(segment) - end - end - end - - destination.close - - # Check the checksum of the new file to verify that it - # downloaded properly. This shouldn't happen, but it can! - if checksum.checksum != box["checksum"] - puts "Checksum didn't match! Download was corrupt!" - abort - end - end + desc "shows components that can be tested" + task :components do + exec("vagrant-spec components --config=vagrant-spec.config.rb") end - desc "Generates the configuration for acceptance tests from current source." - task :config, :box_dir do |t, args| - require File.expand_path("../../lib/vagrant/version", __FILE__) - require File.expand_path('../../test/support/tempdir', __FILE__) + desc "runs acceptance tests" + task :run do + args = [ + "--config=vagrant-spec.config.rb", + ] - # Get the directory for the boxes - box_dir = Pathname.new(args[:box_dir] || File.expand_path("../../boxes", __FILE__)) - - # Generate the binstubs for the Vagrant binary - tempdir = Tempdir.new - process = ChildProcess.build("bundle", "install", "--binstubs", tempdir.path) - process.io.inherit! - process.start - process.poll_for_exit(64000) - if process.exit_code != 0 - # Bundle install failed... - puts "Bundle install failed!" - abort + if ENV["COMPONENTS"] + args << "--components=\"#{ENV["COMPONENTS"]}\"" end - # Generate the actual configuration - config = { - "vagrant_path" => File.join(tempdir.path, "vagrant"), - "vagrant_version" => Vagrant::VERSION, - "env" => { - "BUNDLE_GEMFILE" => File.expand_path("../../Gemfile", __FILE__) - }, - "box_directory" => box_dir.to_s - } - - File.open("acceptance_config.yml", "w+") do |f| - f.write(YAML.dump(config)) - end - - puts <<-OUTPUT -Acceptance test configuration is now in this directory in -"acceptance_config.yml." Set your ACCEPTANCE_CONFIG environmental -variable to this file and run any of the acceptance tests now. -OUTPUT + command = "vagrant-spec test #{args.join(" ")}" + puts command + puts + exec(command) end end diff --git a/tasks/test.rake b/tasks/test.rake index da984db0d..18e4395b1 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -11,9 +11,4 @@ namespace :test do t.libs << "test/unit_legacy" t.pattern = "test/unit_legacy/**/*_test.rb" end - - RSpec::Core::RakeTask.new(:acceptance) do |t| - $: << File.expand_path("../test/acceptance", __FILE__) - t.pattern = "test/acceptance/**/*_test.rb" - end end From 3a15cdd8e4dd7ba7cb5cce7ba74f821607eff718 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 14:31:25 -0800 Subject: [PATCH 5/6] Update README --- README.md | 45 +++++++++++++++------------------- vagrant-spec.config.example.rb | 5 +++- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 666dac378..9f2c64f9d 100644 --- a/README.md +++ b/README.md @@ -54,36 +54,31 @@ This will run the unit test suite, which should come back all green! Then you're If you want to run Vagrant without having to install the gem, you may use `bundle exec`, like so: - bundle exec bin/vagrant help + bundle exec vagrant help ### Acceptance Tests -Vagrant also comes with an acceptance test suite which runs the system -end-to-end, without mocking out any dependencies. Note that this test -suite is **extremely slow**, with the test suite taking hours on even -a decent system. A CI will be setup in due time to run these tests -automatically. However, it is still useful to know how to run these -tests since it is often useful to run a single test if you're working -on a specific feature. +Vagrant also comes with an acceptance test suite that does black-box +tests of various Vagrant components. Note that these tests are **extremely +slow** because actual VMs are spun up and down. The full test suite can +take hours. Instead, try to run focused component tests. -The acceptance tests have absolutely _zero_ dependence on the Vagrant -source. Instead, an external configuration file must be used to give -the acceptance tests some parameters (such as what Vagrant version is -running, where the Vagrant `vagrant` binary is, etc.). If you want to -run acceptance tests against source, or just want to see an example of -this file, you can generate it automatically for the source code: +To run the acceptance test suite, first copy `vagrant-spec.config.example.rb` +to `vagrant-spec.config.rb` and modify it to valid values. The places you +should fill in are clearly marked. - rake acceptance:config +Next, see the components that can be tested: -This will drop an `acceptance_config.yml` file in your working directory. -You can then run a specific acceptance test like so: +``` +$ rake acceptance:components +cli +provider/virtualbox/basic +... +``` - ACCEPTANCE_CONFIG=./acceptance_config.yml ruby test/acceptance/version_test.rb +Then, run one of those components: -That's it! - -If you're developing an acceptance test and you're unsure why things -might be failing, you can also view log output for the acceptance tests, -which can be very verbose but are a great help in finding bugs: - - ACCEPTANCE_LOGGING=debug ACCEPTANCE_CONFIG=./acceptance_config.yml ruby test/acceptance/version_test.rb +``` +$ rake acceptance:run COMPONENTS="cli" +... +``` diff --git a/vagrant-spec.config.example.rb b/vagrant-spec.config.example.rb index 24c42e2df..7f954ffb5 100644 --- a/vagrant-spec.config.example.rb +++ b/vagrant-spec.config.example.rb @@ -1,4 +1,7 @@ +require_relative "test/acceptance/base" + Vagrant::Spec::Acceptance.configure do |c| c.provider "virtualbox", - box_basic: "/Users/mitchellh/Downloads/package.box" + box_basic: "", + contexts: ["provider/virtualbox"] end From 77100ad417ed542a2156f43e623851e11690ba6b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Dec 2013 14:32:16 -0800 Subject: [PATCH 6/6] Update gemfile for others --- Gemfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 309e871f0..3ddf8ced5 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,8 @@ source "http://rubygems.org" gemspec -gem 'vagrant-spec', path: "../vagrant-spec" +if File.exist?(File.expand_path("../../vagrant-spec", __FILE__)) + gem 'vagrant-spec', path: "../vagrant-spec" +else + gem 'vagrant-spec', git: "https://github.com/mitchellh/vagrant-spec.git" +end