|
| 1 | +#! /usr/bin/env ruby -S rspec |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe "the enclose_ipv6 function" do |
| 5 | + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } |
| 6 | + |
| 7 | + it "should exist" do |
| 8 | + expect(Puppet::Parser::Functions.function("enclose_ipv6")).to eq("function_enclose_ipv6") |
| 9 | + end |
| 10 | + |
| 11 | + it "should raise a ParseError if there is less than 1 arguments" do |
| 12 | + expect { scope.function_enclose_ipv6([]) }.to( raise_error(Puppet::ParseError) ) |
| 13 | + end |
| 14 | + |
| 15 | + it "should raise a ParseError if there is more than 1 arguments" do |
| 16 | + expect { scope.function_enclose_ipv6(['argument1','argument2']) }.to( raise_error(Puppet::ParseError) ) |
| 17 | + end |
| 18 | + |
| 19 | + it "should raise a ParseError when given garbage" do |
| 20 | + expect { scope.function_enclose_ipv6(['garbage']) }.to( raise_error(Puppet::ParseError) ) |
| 21 | + end |
| 22 | + |
| 23 | + it "should raise a ParseError when given something else than a string or an array" do |
| 24 | + expect { scope.function_enclose_ipv6([['1' => '127.0.0.1']]) }.to( raise_error(Puppet::ParseError) ) |
| 25 | + end |
| 26 | + |
| 27 | + it "should not raise a ParseError when given a single ip string" do |
| 28 | + expect { scope.function_enclose_ipv6(['127.0.0.1']) }.to_not raise_error |
| 29 | + end |
| 30 | + |
| 31 | + it "should not raise a ParseError when given * as ip string" do |
| 32 | + expect { scope.function_enclose_ipv6(['*']) }.to_not raise_error |
| 33 | + end |
| 34 | + |
| 35 | + it "should not raise a ParseError when given an array of ip strings" do |
| 36 | + expect { scope.function_enclose_ipv6([['127.0.0.1','fe80::1']]) }.to_not raise_error |
| 37 | + end |
| 38 | + |
| 39 | + it "should not raise a ParseError when given differently notations of ip addresses" do |
| 40 | + expect { scope.function_enclose_ipv6([['127.0.0.1','fe80::1','[fe80::1]']]) }.to_not raise_error |
| 41 | + end |
| 42 | + |
| 43 | + it "should raise a ParseError when given a wrong ipv4 address" do |
| 44 | + expect { scope.function_enclose_ipv6(['127..0.0.1']) }.to( raise_error(Puppet::ParseError) ) |
| 45 | + end |
| 46 | + |
| 47 | + it "should raise a ParseError when given a ipv4 address with square brackets" do |
| 48 | + expect { scope.function_enclose_ipv6(['[127.0.0.1]']) }.to( raise_error(Puppet::ParseError) ) |
| 49 | + end |
| 50 | + |
| 51 | + it "should raise a ParseError when given a wrong ipv6 address" do |
| 52 | + expect { scope.function_enclose_ipv6(['fe80:::1']) }.to( raise_error(Puppet::ParseError) ) |
| 53 | + end |
| 54 | + |
| 55 | + it "should embrace ipv6 adresses within an array of ip addresses" do |
| 56 | + result = scope.function_enclose_ipv6([['127.0.0.1','fe80::1','[fe80::2]']]) |
| 57 | + expect(result).to(eq(['127.0.0.1','[fe80::1]','[fe80::2]'])) |
| 58 | + end |
| 59 | + |
| 60 | + it "should embrace a single ipv6 adresse" do |
| 61 | + result = scope.function_enclose_ipv6(['fe80::1']) |
| 62 | + expect(result).to(eq(['[fe80::1]'])) |
| 63 | + end |
| 64 | + |
| 65 | + it "should not embrace a single ipv4 adresse" do |
| 66 | + result = scope.function_enclose_ipv6(['127.0.0.1']) |
| 67 | + expect(result).to(eq(['127.0.0.1'])) |
| 68 | + end |
| 69 | +end |
0 commit comments