From 0dd2b2dd4134bddcb5a3399b001147400f97a4f5 Mon Sep 17 00:00:00 2001 From: NAshwini Date: Thu, 28 Jun 2018 17:11:19 +0530 Subject: [PATCH] Add unit spec Signed-off-by: NAshwini --- spec/unit/report/fetcher_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/unit/report/fetcher_spec.rb b/spec/unit/report/fetcher_spec.rb index 0728306d..bc8e8d5a 100644 --- a/spec/unit/report/fetcher_spec.rb +++ b/spec/unit/report/fetcher_spec.rb @@ -19,6 +19,7 @@ require 'spec_helper' require_relative '../../../files/default/vendor/chef-server/fetcher' +require "byebug" describe ChefServer::Fetcher do let(:mynode) { Chef::Node.new } @@ -33,6 +34,9 @@ let(:profile_hash_target) { '/organizations/org/owners/user/compliance/linux-baseline/version/2.1.0/tar' } + let(:non_profile_url){ + 'http://127.0.0.1:8889/organizations/org/owners/user/compliance/linux-baseline/version/2.1.0/tar' + } context 'when target is a string' do before :each do @@ -70,4 +74,28 @@ expect(res.target.request_uri).to eq(profile_hash_target) end end + + context 'when profile not found' do + before :each do + Chef::Config[:verify_api_cert] = false + Chef::Config[:ssl_verify_mode] = :verify_none + allow(Chef).to receive(:node).and_return(mynode) + end + + it 'should raise error' do + myproc = proc { + config = { + 'server_type' => 'automate', + 'automate' => { + 'ent' => 'my_ent', + 'token_type' => 'dctoken', + }, + 'profile' => ['admin', 'linux-baseline', '2.0'] + } + + Fetchers::Url.new('non_profile_url', config).send(:http_opts) + } + expect {myproc.call}.to raise_error(RuntimeError) + end + end end