File: cisco_spec.rb

package info (click to toggle)
puppet 5.5.10-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,116 kB
  • sloc: ruby: 250,669; sh: 1,620; xml: 218; makefile: 151; sql: 103
file content (55 lines) | stat: -rw-r--r-- 1,910 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/provider/vlan/cisco'

provider_class = Puppet::Type.type(:vlan).provider(:cisco)

describe provider_class do
  before do
    @device = stub_everything 'device'
    @resource = stub("resource", :name => "200")
    @provider = provider_class.new(@device, @resource)
  end

  it "should have a parent of Puppet::Provider::Cisco" do
    expect(provider_class).to be < Puppet::Provider::Cisco
  end

  it "should have an instances method" do
    expect(provider_class).to respond_to(:instances)
  end

  describe "when looking up instances at prefetch" do
    before do
      @device.stubs(:command).yields(@device)
    end

    it "should delegate to the device vlans" do
      @device.expects(:parse_vlans)
      provider_class.lookup(@device, "200")
    end

    it "should return only the given vlan" do
      @device.expects(:parse_vlans).returns({"200" => { :description => "thisone" }, "1" => { :description => "nothisone" }})
      expect(provider_class.lookup(@device, "200")).to eq({:description => "thisone" })
    end

  end

  describe "when an instance is being flushed" do
    it "should call the device update_vlan method with its vlan id, current attributes, and desired attributes" do
      @instance = provider_class.new(@device, :ensure => :present, :name => "200", :description => "myvlan")
      @instance.description = "myvlan2"
      @instance.resource = @resource
      @resource.stubs(:[]).with(:name).returns("200")
      device = stub_everything 'device'
      @instance.stubs(:device).returns(device)
      device.expects(:command).yields(device)
      device.expects(:update_vlan).with(@instance.name, {:ensure => :present, :name => "200", :description => "myvlan"},
                                                   {:ensure => :present, :name => "200", :description => "myvlan2"})

      @instance.flush
    end
  end
end