summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/zone_spec.rb
blob: eb3d33bb0213d38000981bbd68a6c80e69db01a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env rspec
require 'spec_helper'

zone = Puppet::Type.type(:zone)

describe zone do
  before do
    zone = Puppet::Type.type(:zone)
    provider = stub 'provider'
    provider.stubs(:name).returns(:solaris)
    zone.stubs(:defaultprovider).returns(provider)
    resource = stub 'resource', :resource => nil, :provider => provider, :line => nil, :file => nil
  end

  parameters = [:create_args, :install_args, :sysidcfg, :path, :realhostname]

  parameters.each do |parameter|
    it "should have a #{parameter} parameter" do
      zone.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
    end
  end

  properties = [:ip, :iptype, :autoboot, :pool, :shares, :inherit]

  properties.each do |property|
    it "should have a #{property} property" do
      zone.attrclass(property).ancestors.should be_include(Puppet::Property)
    end
  end

  it "should be invalid when :path is missing" do
    lambda { zone.new(:name => "dummy") }.should raise_error
  end

  it "should be invalid when :ip is missing a \":\" and iptype is :shared" do
    lambda { zone.new(:name => "dummy", :ip => "if") }.should raise_error
  end

  it "should be invalid when :ip has a \":\" and iptype is :exclusive" do
    lambda { zone.new(:name => "dummy", :ip => "if:1.2.3.4", :iptype => :exclusive) }.should raise_error
  end

  it "should be invalid when :ip has two \":\" and iptype is :exclusive" do
    lambda { zone.new(:name => "dummy", :ip => "if:1.2.3.4:2.3.4.5", :iptype => :exclusive) }.should raise_error
  end

  it "should be valid when :iptype is :shared and using interface and ip" do
    zone.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4")
  end

  it "should be valid when :iptype is :shared and using interface, ip and default route" do
    zone.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4:2.3.4.5")
  end

  it "should be valid when :iptype is :exclusive and using interface" do
    zone.new(:name => "dummy", :path => "/dummy", :ip => "if", :iptype => :exclusive)
  end

  it "should auto-require :dataset entries" do
    fs = 'random-pool/some-zfs'

    # ick
    provider = stub 'zfs::provider'
    provider.stubs(:name).returns(:solaris)
    Puppet::Type.type(:zfs).stubs(:defaultprovider).returns(provider)

    catalog = Puppet::Resource::Catalog.new
    zfs_instance = Puppet::Type.type(:zfs).new(:name => fs)
    catalog.add_resource zfs_instance

    zone_instance = zone.new(:name    => "dummy",
                             :path    => "/foo",
                             :ip      => 'en1:1.0.0.0',
                             :dataset => fs)
    catalog.add_resource zone_instance

    catalog.relationship_graph.dependencies(zone_instance).should == [zfs_instance]
  end
end