Fix tests

This commit is contained in:
Seth Vargo 2016-07-18 21:31:25 -04:00
parent 7868421a21
commit 1849990517
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
20 changed files with 55 additions and 235 deletions

View File

@ -20,17 +20,17 @@ describe "VagrantPlugins::GuestCoreOS::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
comm.expect_command("hostname 'banana-rama'")
described_class.change_host_name(machine, hostname)
described_class.change_host_name(machine, name)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -20,11 +20,11 @@ describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 1)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
described_class.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/scutil --set ComputerName 'banana-rama.example.com'/)
expect(comm.received_commands[1]).to match(/scutil --set HostName 'banana-rama.example.com'/)
expect(comm.received_commands[1]).to match(/scutil --set LocalHostName 'banana-rama'/)
@ -32,8 +32,8 @@ describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -27,9 +27,7 @@ describe "VagrantPlugins::GuestDebian::Cap::ChangeHostName" do
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname -F \/etc\/hostname/)
expect(comm.received_commands[1]).to match(/invoke-rc.d hostname.sh start/)
expect(comm.received_commands[1]).to match(/invoke-rc.d networking force-reload/)
expect(comm.received_commands[1]).to match(/invoke-rc.d network-manager force-reload/)
expect(comm.received_commands[1]).to match(/hostname.sh start/)
end
it "does not set the hostname if unset" do

View File

@ -20,19 +20,11 @@ describe "VagrantPlugins::GuestDebian::Cap:RSync" do
end
describe ".rsync_install" do
it "installs rsync when not installed" do
comm.stub_command("command -v rsync", exit_code: 1)
it "installs rsync" do
described_class.rsync_install(machine)
expect(comm.received_commands[1]).to match(/apt-get -yqq update/)
expect(comm.received_commands[1]).to match(/apt-get -yqq install rsync/)
end
it "does not install rsync when installed" do
comm.stub_command("command -v rsync", exit_code: 0)
described_class.rsync_install(machine)
expect(comm.received_commands.join("")).to_not match(/update/)
expect(comm.received_commands[0]).to match(/apt-get -yqq update/)
expect(comm.received_commands[0]).to match(/apt-get -yqq install rsync/)
end
end
end

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname if unset" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/nodename/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do
end
it "does not set the hostname if set" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)

View File

@ -26,7 +26,7 @@ describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/hostname/)
@ -34,7 +34,7 @@ describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,14 +24,14 @@ describe "VagrantPlugins::GuestPld::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname '#{name}'/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,17 +24,18 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/\/etc\/sysconfig\/network/)
expect(comm.received_commands[1]).to match(/\/etc\/sysconfig\/network-scripts\/ifcfg/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{name}'/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname --static '#{name}'/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname --transient '#{name}'/)
expect(comm.received_commands[1]).to match(/service network restart/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -49,20 +49,6 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do
}
end
it "uses fedora for rhel7 configuration" do
require_relative "../../../../../../plugins/guests/fedora/cap/configure_networks"
allow(guest).to receive(:capability)
.with(:flavor)
.and_return(:rhel_7)
allow(VagrantPlugins::GuestFedora::Cap::ConfigureNetworks)
.to receive(:configure_networks)
expect(VagrantPlugins::GuestFedora::Cap::ConfigureNetworks)
.to receive(:configure_networks).once
cap.configure_networks(machine, [network_1, network_2])
end
it "creates and starts the networks" do
allow(guest).to receive(:capability)
.with(:flavor)

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestSlackware::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/hostname/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestSlackware::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/HOSTNAME/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -1,42 +0,0 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestUbuntu::Cap::ChangeHostName" do
let(:caps) do
VagrantPlugins::GuestUbuntu::Plugin
.components
.guest_capabilities[:ubuntu]
end
let(:machine) { double("machine") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
end
after do
comm.verify_expectations!
end
describe ".change_host_name" do
let(:cap) { caps.get(:change_host_name) }
let(:name) { 'banana-rama.example.com' }
it "sets the hostname if not set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname -F \/etc\/hostname/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/hostname.sh start/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/hostname start/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/networking force-reload/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/network-manager force-reload/)
end
it "does not set the hostname if unset" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end
end

View File

@ -9,6 +9,7 @@ describe "templates/guests/arch/network_static" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "eth1",
ip: "1.1.1.1",
netmask: "24",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
Connection=ethernet
@ -24,6 +25,7 @@ describe "templates/guests/arch/network_static" do
device: "eth1",
ip: "1.1.1.1",
gateway: "1.2.3.4",
netmask: "24",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
Connection=ethernet

View File

@ -1,21 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_dhcp" do
let(:template) { "guests/fedora/network_dhcp" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=en0
#VAGRANT-END
EOH
end
end

View File

@ -1,25 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_static6" do
let(:template) { "guests/fedora/network_static6" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "fc00::10/64"
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPV6INIT=yes
IPV6ADDR=fc00::10/64
DEVICE=en0
#VAGRANT-END
EOH
end
end

View File

@ -1,71 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_static" do
let(:template) { "guests/fedora/network_static" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
PEERDNS=no
#VAGRANT-END
EOH
end
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
gateway: "1.2.3.4",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
GATEWAY=1.2.3.4
PEERDNS=no
#VAGRANT-END
EOH
end
it "includes the mac_address" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
mac_address: "abcd1234",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
HWADDR=abcd1234
PEERDNS=no
#VAGRANT-END
EOH
end
end

View File

@ -7,12 +7,12 @@ describe "templates/guests/gentoo/network_dhcp" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0="dhcp"
config_en0="dhcp"
#VAGRANT-END
EOH
end

View File

@ -7,21 +7,21 @@ describe "templates/guests/gentoo/network_static" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0=("1.1.1.1 netmask 255.255.0.0")
config_en0=("1.1.1.1 netmask 255.255.0.0")
#VAGRANT-END
EOH
end
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
gateway: "1.2.3.4",
@ -29,8 +29,8 @@ describe "templates/guests/gentoo/network_static" do
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0=("1.1.1.1 netmask 255.255.0.0")
gateways_ethen0="1.2.3.4"
config_en0=("1.1.1.1 netmask 255.255.0.0")
gateways_en0="1.2.3.4"
#VAGRANT-END
EOH
end

View File

@ -7,14 +7,14 @@ describe "templates/guests/redhat/network_dhcp" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=ethen0
DEVICE=en0
#VAGRANT-END
EOH
end

View File

@ -7,7 +7,7 @@ describe "templates/guests/redhat/network_static" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
@ -19,7 +19,7 @@ describe "templates/guests/redhat/network_static" do
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=ethen0
DEVICE=en0
PEERDNS=no
#VAGRANT-END
EOH
@ -27,7 +27,7 @@ describe "templates/guests/redhat/network_static" do
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
ip: "1.1.1.1",
gateway: "1.2.3.4",
netmask: "255.255.0.0",
@ -40,7 +40,7 @@ describe "templates/guests/redhat/network_static" do
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=ethen0
DEVICE=en0
GATEWAY=1.2.3.4
PEERDNS=no
#VAGRANT-END