From 8efb8daf0752e82d66d129eb32a83a7b683619fa Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 13 Aug 2013 22:39:32 -0300 Subject: [PATCH] Implement some initial sanity checks using Bats Somehow related to GH-1 --- .../fixtures/auto-detect-with-provisioning.rb | 9 ++++ spec/acceptance/fixtures/auto-detect.rb | 7 +++ spec/acceptance/fixtures/no-cachier-simple.rb | 5 +++ .../fixtures/no-cachier-with-provisioning.rb | 6 +++ spec/acceptance/sanity_check.bats | 45 +++++++++++++++++++ spec/acceptance/test_helper.bash | 26 +++++++++++ 6 files changed, 98 insertions(+) create mode 100644 spec/acceptance/fixtures/auto-detect-with-provisioning.rb create mode 100644 spec/acceptance/fixtures/auto-detect.rb create mode 100644 spec/acceptance/fixtures/no-cachier-simple.rb create mode 100644 spec/acceptance/fixtures/no-cachier-with-provisioning.rb create mode 100644 spec/acceptance/sanity_check.bats create mode 100644 spec/acceptance/test_helper.bash diff --git a/spec/acceptance/fixtures/auto-detect-with-provisioning.rb b/spec/acceptance/fixtures/auto-detect-with-provisioning.rb new file mode 100644 index 0000000..79de78a --- /dev/null +++ b/spec/acceptance/fixtures/auto-detect-with-provisioning.rb @@ -0,0 +1,9 @@ +Vagrant.require_plugin 'vagrant-cachier' +Vagrant.require_plugin 'vagrant-lxc' +Vagrant.configure("2") do |config| + config.cache.auto_detect = true + config.cache.scope = :machine + + config.vm.box = 'raring64' + config.vm.provision :shell, inline: 'apt-get update && apt-get install -y git' +end diff --git a/spec/acceptance/fixtures/auto-detect.rb b/spec/acceptance/fixtures/auto-detect.rb new file mode 100644 index 0000000..0027d7f --- /dev/null +++ b/spec/acceptance/fixtures/auto-detect.rb @@ -0,0 +1,7 @@ +Vagrant.require_plugin 'vagrant-cachier' +Vagrant.require_plugin 'vagrant-lxc' +Vagrant.configure("2") do |config| + config.cache.auto_detect = true + config.vm.box = 'quantal64' + config.vm.provision :shell, inline: 'echo Hello!' +end diff --git a/spec/acceptance/fixtures/no-cachier-simple.rb b/spec/acceptance/fixtures/no-cachier-simple.rb new file mode 100644 index 0000000..ad2eff0 --- /dev/null +++ b/spec/acceptance/fixtures/no-cachier-simple.rb @@ -0,0 +1,5 @@ +Vagrant.require_plugin 'vagrant-cachier' +Vagrant.require_plugin 'vagrant-lxc' +Vagrant.configure("2") do |config| + config.vm.box = 'quantal64' +end diff --git a/spec/acceptance/fixtures/no-cachier-with-provisioning.rb b/spec/acceptance/fixtures/no-cachier-with-provisioning.rb new file mode 100644 index 0000000..674ef25 --- /dev/null +++ b/spec/acceptance/fixtures/no-cachier-with-provisioning.rb @@ -0,0 +1,6 @@ +Vagrant.require_plugin 'vagrant-cachier' +Vagrant.require_plugin 'vagrant-lxc' +Vagrant.configure("2") do |config| + config.vm.box = 'quantal64' + config.vm.provision :shell, inline: 'echo Hello!' +end diff --git a/spec/acceptance/sanity_check.bats b/spec/acceptance/sanity_check.bats new file mode 100644 index 0000000..9635b3b --- /dev/null +++ b/spec/acceptance/sanity_check.bats @@ -0,0 +1,45 @@ +#!/usr/bin/env bats + +load test_helper + +@test "Vagrantfile without cachier statement does not blow up when bringing the VM up" { + configure_env "no-cachier-simple.rb" + vagrant_up + [ "$status" -eq 0 ] + vagrant_destroy + + configure_env "no-cachier-with-provisioning.rb" + vagrant_up + [ "$status" -eq 0 ] + vagrant_destroy +} + +@test "Vagrantfile with cachier auto_detect statement does not blow up when bringing the VM up" { + configure_env "auto-detect.rb" + vagrant_up + [ "$status" -eq 0 ] + vagrant_destroy +} + +@test "APT cache bucket configures the cache dir properly and keeps cache dir around" { + configure_env "auto-detect-with-provisioning.rb" + + # Make sure cache dir does not exist + test ! -d tmp/.vagrant/machines/default/cache/apt + + vagrant_up + [ "$status" -eq 0 ] + + # Make sure packages are being cached + test -d tmp/.vagrant/machines/default/cache/apt + FILES=(`ls tmp/.vagrant/machines/default/cache/apt/git*.deb`) + [ ${#FILES[@]} -gt 0 ] + + vagrant_destroy + + # Make sure packages are not removed between machine rebuilds + FILES=(`ls tmp/.vagrant/machines/default/cache/apt/git*.deb`) + [ ${#FILES[@]} -gt 0 ] + + empty_cache +} diff --git a/spec/acceptance/test_helper.bash b/spec/acceptance/test_helper.bash new file mode 100644 index 0000000..48cc788 --- /dev/null +++ b/spec/acceptance/test_helper.bash @@ -0,0 +1,26 @@ +vagrant_up() { + pushd tmp + run bundle exec vagrant up > /tmp/vagrant-cachier-tests.log + popd +} + +vagrant_destroy() { + pushd tmp + run bundle exec vagrant destroy -f + popd +} + +configure_env() { + fixture=$1 + + mkdir -p tmp/ + cp spec/acceptance/fixtures/${fixture} tmp/Vagrantfile + + vagrant_destroy + [ "$status" -eq 0 ] + rm -rf tmp/.vagrant +} + +empty_cache() { + rm -rf tmp/.vagrant/cache +}