Added tests
Signed-off-by: Fabio Rapposelli <fabio@vmware.com>
This commit is contained in:
parent
21db4470a0
commit
90bb760b3b
|
@ -19,6 +19,21 @@ module VagrantPlugins
|
||||||
networks.each do |network|
|
networks.each do |network|
|
||||||
comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}")
|
comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
primary_machine_config = machine.env.active_machines.first
|
||||||
|
primary_machine = machine.env.machine(*primary_machine_config, true)
|
||||||
|
|
||||||
|
get_ip = lambda do |machine|
|
||||||
|
ip = nil
|
||||||
|
machine.config.vm.networks.each do |type, opts|
|
||||||
|
if type == :private_network && opts[:ip]
|
||||||
|
ip = opts[:ip]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
# Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
require File.expand_path("../../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
|
||||||
|
let(:described_class) do
|
||||||
|
VagrantPlugins::GuestPhoton::Plugin.components.guest_capabilities[:photon].get(:change_host_name)
|
||||||
|
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 change hostname when hostname is differ from current' do
|
||||||
|
hostname = 'vagrant-photon'
|
||||||
|
expect(communicator).to receive(:test).with("sudo hostname --fqdn | grep 'vagrant-photon'")
|
||||||
|
communicator.should_receive(:sudo).with("hostname #{hostname.split('.')[0]}")
|
||||||
|
described_class.change_host_name(machine, hostname)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not change hostname when hostname equals current' do
|
||||||
|
hostname = 'vagrant-photon'
|
||||||
|
communicator.stub(:test).and_return(true)
|
||||||
|
communicator.should_not_receive(:sudo)
|
||||||
|
described_class.change_host_name(machine, hostname)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,40 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
# Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
require File.expand_path("../../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe "VagrantPlugins::GuestPhoton::Cap::ConfigureNetworks" do
|
||||||
|
let(:described_class) do
|
||||||
|
VagrantPlugins::GuestPhoton::Plugin.components.guest_capabilities[:photon].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 => 1, :name => 'eth0' },
|
||||||
|
{ :type => :dhcp, :interface => 2, :name => 'eth1' },
|
||||||
|
{ :type => :static, :ip => '10.168.10.10', :netmask => '255.255.0.0', :interface => 3, :name => 'docker0' }
|
||||||
|
]
|
||||||
|
communicator.should_receive(:sudo).with("ifconfig | grep 'eth' | cut -f1 -d' '")
|
||||||
|
communicator.should_receive(:sudo).with('ifconfig 192.168.10.10 netmask 255.255.255.0')
|
||||||
|
communicator.should_receive(:sudo).with('ifconfig netmask ')
|
||||||
|
communicator.should_receive(:sudo).with('ifconfig 10.168.10.10 netmask 255.255.0.0')
|
||||||
|
|
||||||
|
allow_message_expectations_on_nil
|
||||||
|
machine.should_receive(:env).at_least(5).times
|
||||||
|
machine.env.should_receive(:active_machines).at_least(:twice)
|
||||||
|
machine.env.active_machines.should_receive(:first)
|
||||||
|
machine.env.should_receive(:machine)
|
||||||
|
|
||||||
|
described_class.configure_networks(machine, networks)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,26 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
# Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
require File.expand_path("../../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe "VagrantPlugins::GuestPhoton::Cap::Docker" do
|
||||||
|
let(:described_class) do
|
||||||
|
VagrantPlugins::GuestPhoton::Plugin.components.guest_capabilities[:photon].get(:docker_daemon_running)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
communicator.verify_expectations!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should check docker' do
|
||||||
|
expect(communicator).to receive(:test).with('test -S /run/docker.sock')
|
||||||
|
described_class.docker_daemon_running(machine)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue