|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe Puppet::Type.type(:oratab) do |
| 6 | + |
| 7 | + before do |
| 8 | + @provider_class = described_class.provide(:fake) { mk_resource_methods } |
| 9 | + @provider_class.stubs(:suitable?).returns true |
| 10 | + described_class.stubs(:defaultprovider).returns @provider_class |
| 11 | + end |
| 12 | + |
| 13 | + it "should have :name as its keyattribute" do |
| 14 | + described_class.key_attributes.should == [:name] |
| 15 | + end |
| 16 | + |
| 17 | + describe "when validating attributes" do |
| 18 | + [:name, :provider].each do |param| |
| 19 | + it "should have a #{param} parameter" do |
| 20 | + described_class.attrtype(param).should == :param |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + [:ensure, :home, :atboot, :description, :target].each do |property| |
| 25 | + it "should have a #{property} property" do |
| 26 | + described_class.attrtype(property).should == :property |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + describe "when validating value" do |
| 32 | + |
| 33 | + describe "for ensure" do |
| 34 | + it "should support present" do |
| 35 | + proc { described_class.new(:name => 'foo', :ensure => :present) }.should_not raise_error |
| 36 | + end |
| 37 | + |
| 38 | + it "should support absent" do |
| 39 | + proc { described_class.new(:name => 'foo', :ensure => :absent) }.should_not raise_error |
| 40 | + end |
| 41 | + |
| 42 | + it "should not support other values" do |
| 43 | + proc { described_class.new(:name => 'foo', :ensure => :foo) }.should raise_error(Puppet::Error, /Invalid value/) |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + describe "for name" do |
| 48 | + it "should support a valid name" do |
| 49 | + proc { described_class.new(:name => 'TEST01E', :ensure => :present) }.should_not raise_error |
| 50 | + proc { described_class.new(:name => 'MY_FANCY_DB', :ensure => :present) }.should_not raise_error |
| 51 | + end |
| 52 | + |
| 53 | + it "should not support whitespace" do |
| 54 | + proc { described_class.new(:name => 'TEST 01E', :ensure => :present) }.should raise_error(Puppet::Error, /Name.*whitespace/) |
| 55 | + proc { described_class.new(:name => 'TEST01E ', :ensure => :present) }.should raise_error(Puppet::Error, /Name.*whitespace/) |
| 56 | + proc { described_class.new(:name => ' TEST01E', :ensure => :present) }.should raise_error(Puppet::Error, /Name.*whitespace/) |
| 57 | + proc { described_class.new(:name => "TEST\t01E", :ensure => :present) }.should raise_error(Puppet::Error, /Name.*whitespace/) |
| 58 | + end |
| 59 | + |
| 60 | + it "should not support an empty name" do |
| 61 | + proc { described_class.new(:name => '', :ensure => :present) }.should raise_error(Puppet::Error, /Name.*empty/) |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + describe "for home" do |
| 66 | + it "should support an absolute path" do |
| 67 | + proc { described_class.new(:name => 'TEST01E', :home => '/my/home', :ensure => :present) }.should_not raise_error |
| 68 | + proc { described_class.new(:name => 'TEST01E', :home => '/my/fancy path', :ensure => :present) }.should_not raise_error |
| 69 | + end |
| 70 | + it "should not support a relative path" do |
| 71 | + proc { described_class.new(:name => 'TEST01E', :home => './my/home', :ensure => :present) }.should raise_error(Puppet::Error, /Home must be an absolute path/) |
| 72 | + proc { described_class.new(:name => 'TEST01E', :home => 'my/home', :ensure => :present) }.should raise_error(Puppet::Error, /Home must be an absolute path/) |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + describe "for atboot" do |
| 77 | + it "should support yes" do |
| 78 | + proc { described_class.new(:name => 'TEST01E', :atboot => :yes) }.should_not raise_error |
| 79 | + end |
| 80 | + |
| 81 | + it "should support no" do |
| 82 | + proc { described_class.new(:name => 'TEST01E', :atboot => :no) }.should_not raise_error |
| 83 | + end |
| 84 | + it "should support Y" do |
| 85 | + proc { described_class.new(:name => 'TEST01E', :atboot => :Y) }.should_not raise_error |
| 86 | + end |
| 87 | + it "should support N" do |
| 88 | + proc { described_class.new(:name => 'TEST01E', :atboot => :N) }.should_not raise_error |
| 89 | + end |
| 90 | + it "should alias Y to yes" do |
| 91 | + described_class.new(:name => 'TEST01E', :atboot => :Y)[:atboot].should == :yes |
| 92 | + end |
| 93 | + it "should alias N to no" do |
| 94 | + described_class.new(:name => 'TEST01E', :atboot => :N)[:atboot].should == :no |
| 95 | + end |
| 96 | + it "should not support other values" do |
| 97 | + proc { described_class.new(:name => 'TEST01E', :atboot => :yess) }.should raise_error(Puppet::Error, /Invalid value/) |
| 98 | + end |
| 99 | + end |
| 100 | + |
| 101 | + describe "for description" do |
| 102 | + it "should support a valid description" do |
| 103 | + proc { described_class.new(:name => 'TEST01E', :description => 'added by agent install') }.should_not raise_error |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + end |
| 108 | +end |
| 109 | + |
0 commit comments