1 #!/usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:has_interface_with) do
7 PuppetlabsSpec::PuppetInternals.scope
10 # The subject of these examples is the method itself.
12 function_name = Puppet::Parser::Functions.function(:has_interface_with)
13 scope.method(function_name)
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
20 scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
22 it 'should have loopback (lo0)' do
23 expect(subject.call(['lo0'])).to be_truthy
25 it 'should not have loopback (lo)' do
26 expect(subject.call(['lo'])).to be_falsey
29 context "On Linux Systems" 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')
39 it 'should have loopback (lo)' do
40 expect(subject.call(['lo'])).to be_truthy
42 it 'should not have loopback (lo0)' do
43 expect(subject.call(['lo0'])).to be_falsey
45 it 'should have ipaddress with 127.0.0.1' do
46 expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy
48 it 'should have ipaddress with 10.0.0.1' do
49 expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy
51 it 'should not have ipaddress with 10.0.0.2' do
52 expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey
54 it 'should have muppet named kermit' do
55 expect(subject.call(['muppet', 'kermit'])).to be_truthy
57 it 'should have muppet named mspiggy' do
58 expect(subject.call(['muppet', 'mspiggy'])).to be_truthy
60 it 'should not have muppet named bigbird' do
61 expect(subject.call(['muppet', 'bigbird'])).to be_falsey