]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/has_interface_with_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / has_interface_with_spec.rb
1 #!/usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:has_interface_with) do
5
6   let(:scope) do
7     PuppetlabsSpec::PuppetInternals.scope
8   end
9
10   # The subject of these examples is the method itself.
11   subject do
12     function_name = Puppet::Parser::Functions.function(:has_interface_with)
13     scope.method(function_name)
14   end
15
16   # We need to mock out the Facts so we can specify how we expect this function
17   # to behave on different platforms.
18   context "On Mac OS X Systems" do
19     before :each do
20       scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
21     end
22     it 'should have loopback (lo0)' do
23       expect(subject.call(['lo0'])).to be_truthy
24     end
25     it 'should not have loopback (lo)' do
26       expect(subject.call(['lo'])).to be_falsey
27     end
28   end
29   context "On Linux Systems" do
30     before :each do
31       scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo')
32       scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1')
33       scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1')
34       scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1')
35       scope.stubs(:lookupvar).with('muppet').returns('kermit')
36       scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy')
37       scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit')
38     end
39     it 'should have loopback (lo)' do
40       expect(subject.call(['lo'])).to be_truthy
41     end
42     it 'should not have loopback (lo0)' do
43       expect(subject.call(['lo0'])).to be_falsey
44     end
45     it 'should have ipaddress with 127.0.0.1' do
46       expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy
47     end
48     it 'should have ipaddress with 10.0.0.1' do
49       expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy
50     end
51     it 'should not have ipaddress with 10.0.0.2' do
52       expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey
53     end
54     it 'should have muppet named kermit' do
55       expect(subject.call(['muppet', 'kermit'])).to be_truthy
56     end
57     it 'should have muppet named mspiggy' do
58       expect(subject.call(['muppet', 'mspiggy'])).to be_truthy
59     end
60     it 'should not have muppet named bigbird' do
61       expect(subject.call(['muppet', 'bigbird'])).to be_falsey
62     end
63   end
64 end