Skip to content

Commit

Permalink
Adding required attribute true
Browse files Browse the repository at this point in the history
  • Loading branch information
shruthiv committed Oct 6, 2015
1 parent 063aa89 commit 3763ceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 5 additions & 13 deletions libraries/supermarket_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class Chef
class Resource
# Missing top-level class documentation comment
class SupermarketServer < Chef::Resource

def initialize(name, run_context=nil)
def initialize(name, run_context = nil)
super
@resource_name = :supermarket_server
@provider = Chef::Provider::SupermarketServer
Expand All @@ -15,19 +14,19 @@ def initialize(name, run_context=nil)
end

def chef_server_url(arg = nil)
set_or_return(:chef_server_url, arg, kind_of: [String])
set_or_return(:chef_server_url, arg, kind_of: [String], required: true)
end

def chef_oauth2_app_id(arg = nil)
set_or_return(:chef_oauth2_app_id, arg, kind_of: [String])
set_or_return(:chef_oauth2_app_id, arg, kind_of: [String], required: true)
end

def chef_oauth2_secret(arg = nil)
set_or_return(:chef_oauth2_secret, arg, kind_of: [String])
set_or_return(:chef_oauth2_secret, arg, kind_of: [String], required: true)
end

def chef_oauth2_verify_ssl(arg = nil)
set_or_return(:chef_oauth2_verify_ssl, arg, kind_of: [TrueClass, FalseClass])
set_or_return(:chef_oauth2_verify_ssl, arg, kind_of: [TrueClass, FalseClass], required: true)
end
end
end
Expand All @@ -53,13 +52,6 @@ def supermarket_config
end

action :create do
%w(chef_server_url chef_oauth2_app_id chef_oauth2_secret).each do |attr|
unless supermarket_config[attr].is_a?(String)
Chef::Log.fatal("You did not provide the node #{attr} value!")
fail
end
end

template '/etc/supermarket/supermarket.json' do
source 'supermarket.json.erb'
mode '0644'
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/libraries/supermarket_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it 'raises an error' do
expect { chef_run }.to raise_error(RuntimeError)
expect { chef_run }.to raise_exception
end
end

Expand Down Expand Up @@ -56,7 +56,7 @@

context 'When a repository chef-current is specified' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'redhat', version: '6.5', step_into: ['chef_ingredient', 'supermarket_server']) do |node|
runner = ChefSpec::SoloRunner.new(platform: 'redhat', version: '6.5', step_into: %w(chef_ingredient supermarket_server)) do |node|
node.set['supermarket_omnibus']['package_repo'] = 'chef-current'
node.set['supermarket_omnibus']['chef_server_url'] = 'https://chefserver.mycorp.com'
node.set['supermarket_omnibus']['chef_oauth2_app_id'] = 'blahblah'
Expand Down Expand Up @@ -118,7 +118,7 @@

context 'When a package_url is specified, the Rpm provider should be used on RHEL systems' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'redhat', version: '6.5', step_into: ['chef_ingredient', 'supermarket_server']) do |node|
runner = ChefSpec::SoloRunner.new(platform: 'redhat', version: '6.5', step_into: %w(chef_ingredient supermarket_server)) do |node|
node.set['supermarket_omnibus']['package_url'] = 'https://web-dl.packagecloud.io/chef/stable/packages/el/6/supermarket-1.10.1~alpha.0-1.el5.x86_64.rpm'
node.set['supermarket_omnibus']['chef_server_url'] = 'https://chefserver.mycorp.com'
node.set['supermarket_omnibus']['chef_oauth2_app_id'] = 'blahblah'
Expand Down

0 comments on commit 3763ceb

Please sign in to comment.