Sha256: 7f0041cc19e2a6642c00711358a575d3ac791c1e1b05cb769a78ae9d0d92934a

Contents?: true

Size: 1.98 KB

Versions: 22

Compression:

Stored size: 1.98 KB

Contents

require File.expand_path("../../../../base", __FILE__)

require Vagrant.source_root.join("plugins/guests/windows/guest_network")

describe "VagrantPlugins::GuestWindows::GuestNetwork" do

  let(:communicator) { double("communicator") }
  let(:subject) { VagrantPlugins::GuestWindows::GuestNetwork.new(communicator) }

  describe ".is_dhcp_enabled" do
    it "should query the NIC by ordinal index" do
      expect(communicator).to receive(:test).with(
        /.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=7 and DHCPEnabled=True"/).
        and_return(true)
      expect(subject.is_dhcp_enabled(7)).to be_true
    end

    it "should return false for non-DHCP NICs" do
      expect(communicator).to receive(:test).with(
        /.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=8 and DHCPEnabled=True"/).
        and_return(false)
      expect(subject.is_dhcp_enabled(8)).to be_false
    end
  end

  describe ".configure_static_interface" do
    it "should configure IP using netsh" do
      expect(communicator).to receive(:execute).with(
        "netsh interface ip set address \"Local Area Connection 2\" static 192.168.33.10 255.255.255.0").
        and_return(0)
      subject.configure_static_interface(7, "Local Area Connection 2", "192.168.33.10", "255.255.255.0")
    end
  end

  describe ".configure_dhcp_interface" do
    it "should configure DHCP when DHCP is disabled" do
      allow(communicator).to receive(:test).and_return(false) # is DHCP enabled?
      expect(communicator).to receive(:execute).with(
        "netsh interface ip set address \"Local Area Connection 2\" dhcp").
        and_return(0)
      subject.configure_dhcp_interface(7, "Local Area Connection 2")
    end

    it "should not configure DHCP when DHCP is enabled" do
      allow(communicator).to receive(:test).and_return(true) # is DHCP enabled?
      expect(communicator).to_not receive(:execute)
      subject.configure_dhcp_interface(7, "Local Area Connection 2")
    end
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.9.5.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.9.1.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.5.2 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.5.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.4.2 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.4.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.1.2 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.8.1.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/unit/plugins/guests/windows/guest_network_test.rb