summaryrefslogtreecommitdiff
path: root/spec/unit/resource/yum_repository_spec.rb
blob: 353ff7ce2357945e94a38ca082ade0e62577841d (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Author:: Thom May (<thom@chef.io>)
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "spec_helper"

describe Chef::Resource::YumRepository do
  let(:node) { Chef::Node.new }
  let(:events) { Chef::EventDispatch::Dispatcher.new }
  let(:run_context) { Chef::RunContext.new(node, {}, events) }
  let(:resource) { Chef::Resource::YumRepository.new("multiverse", run_context) }

  it "has a resource_name of :yum_repository" do
    expect(resource.resource_name).to eq(:yum_repository)
  end

  it "the repositoryid property is the name_property" do
    expect(resource.repositoryid).to eq("multiverse")
  end

  it "fails if the user provides a repositoryid with a forward slash" do
    expect { resource.repositoryid "foo/bar" }.to raise_error(ArgumentError)
  end

  it "the timeout property expects numeric Strings" do
    expect { resource.timeout "123" }.not_to raise_error(ArgumentError)
    expect { resource.timeout "123foo" }.to raise_error(ArgumentError)
  end

  it "the priority property expects numeric Strings from '1' to '99'" do
    expect { resource.priority "99" }.not_to raise_error(ArgumentError)
    expect { resource.priority "1" }.not_to raise_error(ArgumentError)
    expect { resource.priority "100" }.to raise_error(ArgumentError)
    expect { resource.priority "0" }.to raise_error(ArgumentError)
  end

  it "the failovermethod property accepts 'priority' or 'roundrobin'" do
    expect { resource.failovermethod "priority" }.not_to raise_error(ArgumentError)
    expect { resource.failovermethod "roundrobin" }.not_to raise_error(ArgumentError)
    expect { resource.failovermethod "bob" }.to raise_error(ArgumentError)
  end

  it "the http_caching property accepts 'packages', 'all', or 'none'" do
    expect { resource.http_caching "packages" }.not_to raise_error(ArgumentError)
    expect { resource.http_caching "all" }.not_to raise_error(ArgumentError)
    expect { resource.http_caching "none" }.not_to raise_error(ArgumentError)
    expect { resource.http_caching "bob" }.to raise_error(ArgumentError)
  end

  it "the metadata_expire property accepts a time value or 'never'" do
    expect { resource.metadata_expire "100" }.not_to raise_error(ArgumentError)
    expect { resource.metadata_expire "100d" }.not_to raise_error(ArgumentError)
    expect { resource.metadata_expire "100h" }.not_to raise_error(ArgumentError)
    expect { resource.metadata_expire "100m" }.not_to raise_error(ArgumentError)
    expect { resource.metadata_expire "never" }.not_to raise_error(ArgumentError)
    expect { resource.metadata_expire "100s" }.to raise_error(ArgumentError)
  end

  it "the mirror_expire property accepts a time value" do
    expect { resource.mirror_expire "100" }.not_to raise_error(ArgumentError)
    expect { resource.mirror_expire "100d" }.not_to raise_error(ArgumentError)
    expect { resource.mirror_expire "100h" }.not_to raise_error(ArgumentError)
    expect { resource.mirror_expire "100m" }.not_to raise_error(ArgumentError)
    expect { resource.mirror_expire "never" }.to raise_error(ArgumentError)
  end

  it "the mirrorlist_expire property accepts a time value" do
    expect { resource.mirrorlist_expire "100" }.not_to raise_error(ArgumentError)
    expect { resource.mirrorlist_expire "100d" }.not_to raise_error(ArgumentError)
    expect { resource.mirrorlist_expire "100h" }.not_to raise_error(ArgumentError)
    expect { resource.mirrorlist_expire "100m" }.not_to raise_error(ArgumentError)
    expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError)
  end

  context "on linux", :linux_only do
    it "resolves to a Noop class when yum is not found" do
      expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(false)
      expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
    end

    it "resolves to a YumRepository class when yum is found" do
      expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(true)
      expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::YumRepository)
    end
  end

  context "on windows", :windows_only do
    it "resolves to a NoOp provider" do
      expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop)
    end
  end
end