|
4 | 4 | require_relative "../../../../base"
|
5 | 5 |
|
6 | 6 | describe 'VagrantPlugins::GuestAlpine::Cap::ConfigureNetworks' do
|
7 |
| - let(:described_class) do |
8 |
| - VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:configure_networks) |
9 |
| - end |
10 |
| - let(:machine) { double('machine') } |
11 |
| - let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) } |
| 7 | + let(:described_class) do |
| 8 | + VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:configure_networks) |
| 9 | + end |
| 10 | + let(:machine) { double('machine') } |
| 11 | + let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) } |
| 12 | + |
| 13 | + before do |
| 14 | + allow(machine).to receive(:communicate).and_return(communicator) |
| 15 | + end |
| 16 | + |
| 17 | + after do |
| 18 | + communicator.verify_expectations! |
| 19 | + end |
| 20 | + |
| 21 | + it 'should configure networks' do |
| 22 | + networks = [ |
| 23 | + { type: :static, ip: '192.168.10.10', netmask: '255.255.255.0', interface: 0, name: 'eth0' }, |
| 24 | + { type: :dhcp, interface: 1, name: 'eth1' } |
| 25 | + ] |
| 26 | + |
| 27 | + expect(communicator).to receive(:sudo).with("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre") |
| 28 | + expect(communicator).to receive(:sudo).with("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post") |
| 29 | + expect(communicator).to receive(:sudo).with(/\/sbin\/ifdown eth0/) |
| 30 | + expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth0 2> /dev/null') |
| 31 | + expect(communicator).to receive(:sudo).with(/\/sbin\/ifdown eth1/) |
| 32 | + expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth1 2> /dev/null') |
| 33 | + expect(communicator).to receive(:sudo).with('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces') |
| 34 | + expect(communicator).to receive(:sudo).with('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post') |
| 35 | + expect(communicator).to receive(:sudo).with('/sbin/ifup eth0') |
| 36 | + expect(communicator).to receive(:sudo).with('/sbin/ifup eth1') |
| 37 | + |
| 38 | + allow_message_expectations_on_nil |
| 39 | + |
| 40 | + described_class.configure_networks(machine, networks) |
| 41 | + end |
| 42 | + |
| 43 | + context "dhcp assigned default route" do |
| 44 | + let(:networks) { |
| 45 | + [{type: :dhcp, use_dhcp_assigned_default_route: is_enabled}] |
| 46 | + } |
| 47 | + let(:is_enabled) { false } |
| 48 | + let(:tempfile) { double(:tempfile, binmode: true, close: true, path: "/dev/null") } |
12 | 49 |
|
13 | 50 | before do
|
14 |
| - allow(machine).to receive(:communicate).and_return(communicator) |
| 51 | + allow(Tempfile).to receive(:new).and_return(tempfile) |
15 | 52 | end
|
16 | 53 |
|
17 |
| - after do |
18 |
| - communicator.verify_expectations! |
| 54 | + context "when not enabled" do |
| 55 | + it "should not configure default route" do |
| 56 | + expect(tempfile).not_to receive(:write).with(/post-up route del default dev eth0/) |
| 57 | + |
| 58 | + described_class.configure_networks(machine, networks) |
| 59 | + end |
19 | 60 | end
|
20 | 61 |
|
21 |
| - it 'should configure networks' do |
22 |
| - networks = [ |
23 |
| - { type: :static, ip: '192.168.10.10', netmask: '255.255.255.0', interface: 0, name: 'eth0' }, |
24 |
| - { type: :dhcp, interface: 1, name: 'eth1' } |
25 |
| - ] |
26 |
| - |
27 |
| - expect(communicator).to receive(:sudo).with("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre") |
28 |
| - expect(communicator).to receive(:sudo).with("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post") |
29 |
| - expect(communicator).to receive(:sudo).with(/\/sbin\/ifdown eth0/) |
30 |
| - expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth0 2> /dev/null') |
31 |
| - expect(communicator).to receive(:sudo).with(/\/sbin\/ifdown eth1/) |
32 |
| - expect(communicator).to receive(:sudo).with('/sbin/ip addr flush dev eth1 2> /dev/null') |
33 |
| - expect(communicator).to receive(:sudo).with('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces') |
34 |
| - expect(communicator).to receive(:sudo).with('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post') |
35 |
| - expect(communicator).to receive(:sudo).with('/sbin/ifup eth0') |
36 |
| - expect(communicator).to receive(:sudo).with('/sbin/ifup eth1') |
37 |
| - |
38 |
| - allow_message_expectations_on_nil |
| 62 | + context "when enabled" do |
| 63 | + let(:is_enabled) { true } |
| 64 | + |
| 65 | + it "should configure default route" do |
| 66 | + expect(tempfile).to receive(:write).with(/post-up route del default dev eth0/) |
39 | 67 |
|
40 | 68 | described_class.configure_networks(machine, networks)
|
| 69 | + end |
41 | 70 | end
|
| 71 | + end |
42 | 72 | end
|
0 commit comments