|
| 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 | + subject.call(['lo0']).should be_true |
| 24 | + end |
| 25 | + it 'should not have loopback (lo)' do |
| 26 | + subject.call(['lo']).should be_false |
| 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 | + subject.call(['lo']).should be_true |
| 41 | + end |
| 42 | + it 'should not have loopback (lo0)' do |
| 43 | + subject.call(['lo0']).should be_false |
| 44 | + end |
| 45 | + it 'should have ipaddress with 127.0.0.1' do |
| 46 | + subject.call(['ipaddress', '127.0.0.1']).should be_true |
| 47 | + end |
| 48 | + it 'should have ipaddress with 10.0.0.1' do |
| 49 | + subject.call(['ipaddress', '10.0.0.1']).should be_true |
| 50 | + end |
| 51 | + it 'should not have ipaddress with 10.0.0.2' do |
| 52 | + subject.call(['ipaddress', '10.0.0.2']).should be_false |
| 53 | + end |
| 54 | + it 'should have muppet named kermit' do |
| 55 | + subject.call(['muppet', 'kermit']).should be_true |
| 56 | + end |
| 57 | + it 'should have muppet named mspiggy' do |
| 58 | + subject.call(['muppet', 'mspiggy']).should be_true |
| 59 | + end |
| 60 | + it 'should not have muppet named bigbird' do |
| 61 | + subject.call(['muppet', 'bigbird']).should be_false |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments