]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/base64_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / base64_spec.rb
1 #! /usr/bin/env ruby -S rspec
2
3 require 'spec_helper'
4
5 describe "the base64 function" do
6   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
8   it "should exist" do
9     expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64")
10   end
11
12   it "should raise a ParseError if there are other than 2 arguments" do
13     expect { scope.function_base64([]) }.to(raise_error(Puppet::ParseError))
14     expect { scope.function_base64(["asdf"]) }.to(raise_error(Puppet::ParseError))
15     expect { scope.function_base64(["asdf","moo","cow"]) }.to(raise_error(Puppet::ParseError))
16   end
17
18   it "should raise a ParseError if argument 1 isn't 'encode' or 'decode'" do
19     expect { scope.function_base64(["bees","astring"]) }.to(raise_error(Puppet::ParseError, /first argument must be one of/))
20   end
21
22   it "should raise a ParseError if argument 2 isn't a string" do
23     expect { scope.function_base64(["encode",["2"]]) }.to(raise_error(Puppet::ParseError, /second argument must be a string/))
24   end
25
26   it "should encode a encoded string" do
27     result = scope.function_base64(["encode",'thestring'])
28     expect(result).to match(/\AdGhlc3RyaW5n\n\Z/)
29   end
30   it "should decode a base64 encoded string" do
31     result = scope.function_base64(["decode",'dGhlc3RyaW5n'])
32     expect(result).to eq('thestring')
33   end
34 end