Sha256: 654adbc13f67e529b62203a361146dc63a7500b480507662cb2851b32ac57629

Contents?: true

Size: 1.98 KB

Versions: 17

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

17 entries across 13 versions & 5 rubygems

Version Path
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-2.0.2.0 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-2.0.1.0 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-2.0.0.1 test/unit/plugins/guests/windows/guest_network_test.rb
vagrant-unbundled-1.9.8.1 test/unit/plugins/guests/windows/guest_network_test.rb