Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Commit

Permalink
testing updates, travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
maier committed May 2, 2017
1 parent 729a005 commit c36262f
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.2.3
ruby-2.2.5
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
language: ruby
#before_install:
before_install:
- gem uninstall bundler --all --executables
- gem install bundler --version '~> 1.7.0'
# - sudo apt-get update -qq
# - sudo apt-get install -qq -y bsdtar
# - rvm @global do gem uninstall bundler --all --executables
# - gem uninstall bundler --all --executables
# - gem install bundler --version '~> 1.7.0'
rvm:
- 2.2.3
before_install: gem install bundler --version '~> 1.7.0'
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gemspec
# gemspec

group :development do
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
Expand All @@ -12,5 +12,6 @@ end

group :test do
gem 'rake', '< 11.0'
gem 'rspec'
gem 'rubocop'
end
228 changes: 114 additions & 114 deletions spec/cap/change_host_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,127 +2,127 @@
require 'spec_helper'

describe 'VagrantPlugins::GuestAlpine::Cap::ChangeHostname' do
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:change_host_name)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:old_hostname) { 'oldhostname.olddomain.tld' }

before do
allow(machine).to receive(:communicate).and_return(communicator)
communicator.stub_command('hostname -f', stdout: old_hostname)
end

after do
communicator.verify_expectations!
end

describe '.change_host_name' do
it 'updates /etc/hostname on the machine' do
communicator.expect_command("echo 'newhostname' > /etc/hostname")
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:change_host_name)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:old_hostname) { 'oldhostname.olddomain.tld' }

it 'does nothing when the provided hostname is not different' do
described_class.change_host_name(machine, 'oldhostname.olddomain.tld')
expect(communicator.received_commands).to eq(['hostname -f'])
before do
allow(machine).to receive(:communicate).and_return(communicator)
communicator.stub_command('hostname -f', stdout: old_hostname)
end

it 'refreshes the hostname service with the hostname command' do
communicator.expect_command('hostname -F /etc/hostname')
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
after do
communicator.verify_expectations!
end

it 'renews dhcp on the system with the new hostname' do
communicator.expect_command('ifdown -a; ifup -a; ifup eth0')
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
end
describe '.change_host_name' do
it 'updates /etc/hostname on the machine' do
communicator.expect_command("echo 'newhostname' > /etc/hostname")
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
end

it 'does nothing when the provided hostname is not different' do
described_class.change_host_name(machine, 'oldhostname.olddomain.tld')
expect(communicator.received_commands).to eq(['hostname -f'])
end

it 'refreshes the hostname service with the hostname command' do
communicator.expect_command('hostname -F /etc/hostname')
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
end

it 'renews dhcp on the system with the new hostname' do
communicator.expect_command('ifdown -a; ifup -a; ifup eth0')
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
end

describe 'flipping out the old hostname in /etc/hosts' do
let(:sed_command) do
# Here we run the change_host_name through and extract the recorded sed
# command from the dummy communicator
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
communicator.received_commands.find { |cmd| cmd =~ /^sed/ }
end

# Now we extract the regexp from that sed command so we can do some
# verification on it
let(:expression) { sed_command.sub(%r{^sed -ri '\(.*\)' /etc/hosts$}, "\1") }
let(:search) { Regexp.new(expression.split('@')[1], Regexp::EXTENDED) }
let(:replace) { expression.split('@')[2] }

let(:grep_command) { "grep '#{old_hostname}' /etc/hosts" }

before do
communicator.stub_command(grep_command, exit_code: 0)
end

it 'works on an simple /etc/hosts file' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.olddomain.tld oldhostname
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
RESULT
end

it 'does not modify lines which contain similar hostnames' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.olddomain.tld oldhostname
# common prefix, but different fqdn
192.168.12.34 oldhostname.olddomain.tld.different
# different characters at the dot
192.168.34.56 oldhostname-olddomain.tld
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
# common prefix, but different fqdn
192.168.12.34 oldhostname.olddomain.tld.different
# different characters at the dot
192.168.34.56 oldhostname-olddomain.tld
RESULT
end

it "appends 127.0.1.1 if it isn't there" do
communicator.stub_command(grep_command, exit_code: 1)
described_class.change_host_name(machine, 'newhostname.newdomain.tld')

sed = communicator.received_commands.find { |cmd| cmd =~ /^sed/ }
expect(sed).to be_nil

echo = communicator.received_commands.find { |cmd| cmd =~ /^echo/ }
expect(echo).to_not be_nil
end

context 'when the old fqdn has a trailing dot' do
let(:old_hostname) { 'oldhostname.withtrailing.dot.' }

it 'modifies /etc/hosts properly' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.withtrailing.dot. oldhostname
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
RESULT
describe 'flipping out the old hostname in /etc/hosts' do
let(:sed_command) do
# Here we run the change_host_name through and extract the recorded sed
# command from the dummy communicator
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
communicator.received_commands.find { |cmd| cmd =~ /^sed/ }
end

# Now we extract the regexp from that sed command so we can do some
# verification on it
let(:expression) { sed_command.sub(%r{^sed -ri '\(.*\)' /etc/hosts$}, "\1") }
let(:search) { Regexp.new(expression.split('@')[1], Regexp::EXTENDED) }
let(:replace) { expression.split('@')[2] }

let(:grep_command) { "grep '#{old_hostname}' /etc/hosts" }

before do
communicator.stub_command(grep_command, exit_code: 0)
end

it 'works on an simple /etc/hosts file' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.olddomain.tld oldhostname
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
RESULT
end

it 'does not modify lines which contain similar hostnames' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.olddomain.tld oldhostname
# common prefix, but different fqdn
192.168.12.34 oldhostname.olddomain.tld.different
# different characters at the dot
192.168.34.56 oldhostname-olddomain.tld
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
# common prefix, but different fqdn
192.168.12.34 oldhostname.olddomain.tld.different
# different characters at the dot
192.168.34.56 oldhostname-olddomain.tld
RESULT
end

it "appends 127.0.1.1 if it isn't there" do
communicator.stub_command(grep_command, exit_code: 1)
described_class.change_host_name(machine, 'newhostname.newdomain.tld')

sed = communicator.received_commands.find { |cmd| cmd =~ /^sed/ }
expect(sed).to be_nil

echo = communicator.received_commands.find { |cmd| cmd =~ /^echo/ }
expect(echo).to_not be_nil
end

context 'when the old fqdn has a trailing dot' do
let(:old_hostname) { 'oldhostname.withtrailing.dot.' }

it 'modifies /etc/hosts properly' do
original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 oldhostname.withtrailing.dot. oldhostname
ETC_HOSTS

modified_etc_hosts = original_etc_hosts.gsub(search, replace)

expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '')
127.0.0.1 localhost
127.0.1.1 newhostname.newdomain.tld newhostname
RESULT
end
end
end
end
end
end
end
70 changes: 35 additions & 35 deletions spec/cap/configure_networks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
require 'spec_helper'

describe 'VagrantPlugins::GuestAlpine::Cap::ConfigureNetworks' do
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:configure_networks)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }

before do
allow(machine).to receive(:communicate).and_return(communicator)
end

after do
communicator.verify_expectations!
end

it 'should configure networks' do
networks = [
{ type: :static, ip: '192.168.10.10', netmask: '255.255.255.0', interface: 0, name: 'eth0' },
{ type: :dhcp, interface: 1, name: 'eth1' }
]

communicator.should_receive(:sudo).with("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre")
communicator.should_receive(:sudo).with("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post")
communicator.should_receive(:sudo).with('/sbin/ifdown eth0 2> /dev/null')
communicator.should_receive(:sudo).with('/sbin/ip addr flush dev eth0 2> /dev/null')
communicator.should_receive(:sudo).with('/sbin/ifdown eth1 2> /dev/null')
communicator.should_receive(:sudo).with('/sbin/ip addr flush dev eth1 2> /dev/null')
communicator.should_receive(:sudo).with('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces')
communicator.should_receive(:sudo).with('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post')
communicator.should_receive(:sudo).with('/sbin/ifup eth0')
communicator.should_receive(:sudo).with('/sbin/ifup eth1')

allow_message_expectations_on_nil

described_class.configure_networks(machine, networks)
end
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:configure_networks)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }

before do
allow(machine).to receive(:communicate).and_return(communicator)
end

after do
communicator.verify_expectations!
end

it 'should configure networks' do
networks = [
{ type: :static, ip: '192.168.10.10', netmask: '255.255.255.0', interface: 0, name: 'eth0' },
{ type: :dhcp, interface: 1, name: 'eth1' }
]

expect(communicator).to receive(:sudo).with("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre")
expect(communicator).to receive(:sudo).with("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post")
expect(communicator).to receive(:sudo).with('/sbin/ifdown eth0 2> /dev/null')
expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth0 2> /dev/null')
expect(communicator).to receive(:sudo).with('/sbin/ifdown eth1 2> /dev/null')
expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth1 2> /dev/null')
expect(communicator).to receive(:sudo).with('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces')
expect(communicator).to receive(:sudo).with('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post')
expect(communicator).to receive(:sudo).with('/sbin/ifup eth0')
expect(communicator).to receive(:sudo).with('/sbin/ifup eth1')

allow_message_expectations_on_nil

described_class.configure_networks(machine, networks)
end
end
32 changes: 16 additions & 16 deletions spec/cap/halt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
require 'spec_helper'

describe 'VagrantPlugins::GuestAlpine::Cap::Halt' do
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:halt)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:described_class) do
VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:halt)
end
let(:machine) { double('machine') }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }

before do
allow(machine).to receive(:communicate).and_return(communicator)
end
before do
allow(machine).to receive(:communicate).and_return(communicator)
end

after do
communicator.verify_expectations!
end
after do
communicator.verify_expectations!
end

it 'should halt guest' do
communicator.should_receive(:sudo).with('poweroff')
allow_message_expectations_on_nil
described_class.halt(machine)
end
it 'should halt guest' do
expect(communicator).to receive(:sudo).with('poweroff')
allow_message_expectations_on_nil
described_class.halt(machine)
end
end
Loading

0 comments on commit c36262f

Please sign in to comment.