From 52a120426b87db21cf729303a027fd9d9f70c1a2 Mon Sep 17 00:00:00 2001 From: Reto Kaiser Date: Sun, 6 Dec 2015 20:50:02 +0100 Subject: [PATCH] Add basic acceptance test with vagrant-spec --- .rubocop_todo.yml | 10 ++++++-- Gemfile | 1 + test/acceptance/base.rb | 2 ++ test/acceptance/dns/resolution_host_spec.rb | 23 +++++++++++++++++++ test/acceptance/shared/context_virtualbox.rb | 3 +++ .../skeletons/landrush_basic/Vagrantfile | 8 +++++++ vagrant-spec.config.rb | 8 +++++++ 7 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/acceptance/base.rb create mode 100644 test/acceptance/dns/resolution_host_spec.rb create mode 100644 test/acceptance/shared/context_virtualbox.rb create mode 100644 test/acceptance/skeletons/landrush_basic/Vagrantfile create mode 100644 vagrant-spec.config.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aa16b03..0a867d3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-12-05 08:32:20 +0100 using RuboCop version 0.35.1. +# on 2015-12-06 20:56:09 +0100 using RuboCop version 0.35.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -40,7 +40,7 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 52 +# Offense count: 56 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 157 @@ -156,6 +156,12 @@ Style/EmptyLinesAroundModuleBody: Exclude: - 'test/landrush/cap/linux/read_host_visible_ip_address_test.rb' +# Offense count: 1 +# Configuration parameters: Exclude. +Style/FileName: + Exclude: + - 'vagrant-spec.config.rb' + # Offense count: 6 # Configuration parameters: MinBodyLength. Style/GuardClause: diff --git a/Gemfile b/Gemfile index aebc42b..02c5b95 100644 --- a/Gemfile +++ b/Gemfile @@ -23,4 +23,5 @@ group :development do gem 'byebug' gem 'mocha' + gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git' end diff --git a/test/acceptance/base.rb b/test/acceptance/base.rb new file mode 100644 index 0000000..cab741f --- /dev/null +++ b/test/acceptance/base.rb @@ -0,0 +1,2 @@ +require 'vagrant-spec/acceptance' +require_relative 'shared/context_virtualbox' diff --git a/test/acceptance/dns/resolution_host_spec.rb b/test/acceptance/dns/resolution_host_spec.rb new file mode 100644 index 0000000..8b158ea --- /dev/null +++ b/test/acceptance/dns/resolution_host_spec.rb @@ -0,0 +1,23 @@ +shared_examples 'provider/resolution_host' do |provider, options| + unless options[:box] + fail ArgumentError, "box option must be specified for provider: #{provider}" + end + + include_context 'acceptance' + + before do + environment.skeleton('landrush_basic') + assert_execute('sed', '-i', '', '-e', "s|{{box}}|#{options[:box]}|g", 'Vagrantfile') + assert_execute('vagrant', 'up', "--provider=#{provider}") + end + + after do + assert_execute('vagrant', 'destroy', '--force') + end + + it 'sets up DNS resolution on the host' do + result = execute('dig', '+short', '@localhost', '-p', '10053', 'my-host', 'A') + expect(result).to exit_with(0) + expect(result.stdout).to match(/^10.10.10.123$/) + end +end diff --git a/test/acceptance/shared/context_virtualbox.rb b/test/acceptance/shared/context_virtualbox.rb new file mode 100644 index 0000000..f4270cf --- /dev/null +++ b/test/acceptance/shared/context_virtualbox.rb @@ -0,0 +1,3 @@ +shared_context 'provider-context/virtualbox' do + let(:extra_env) { { 'VBOX_USER_HOME' => '{{homedir}}' } } +end diff --git a/test/acceptance/skeletons/landrush_basic/Vagrantfile b/test/acceptance/skeletons/landrush_basic/Vagrantfile new file mode 100644 index 0000000..03ffa42 --- /dev/null +++ b/test/acceptance/skeletons/landrush_basic/Vagrantfile @@ -0,0 +1,8 @@ +Vagrant.configure('2') do |config| + config.vm.box = '{{box}}' + config.vm.hostname = 'my-host.my-tld' + config.vm.network :private_network, ip: '10.10.10.123' + + config.landrush.enabled = true + config.landrush.tld = 'my-tld' +end diff --git a/vagrant-spec.config.rb b/vagrant-spec.config.rb new file mode 100644 index 0000000..daaeacb --- /dev/null +++ b/vagrant-spec.config.rb @@ -0,0 +1,8 @@ +require_relative 'test/acceptance/base' + +Vagrant::Spec::Acceptance.configure do |c| + c.component_paths = [File.expand_path('../test/acceptance', __FILE__)] + c.skeleton_paths = [File.expand_path('../test/acceptance/skeletons', __FILE__)] + + c.provider 'virtualbox', box: 'debian/wheezy64', contexts: ['provider-context/virtualbox'] +end