-
Notifications
You must be signed in to change notification settings - Fork 19
/
chef_dk_app.rb
146 lines (121 loc) · 3.81 KB
/
chef_dk_app.rb
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# frozen_string_literal: true
require_relative '../resources'
require_relative '../../libraries/helpers'
shared_context 'resources::chef_dk_app' do
include_context 'resources'
let(:resource) { 'chef_dk_app' }
%i(version channel source checksum).each { |p| let(p) { nil } }
let(:properties) do
{ version: version, channel: channel, source: source, checksum: checksum }
end
let(:name) { 'default' }
let(:installed_version) { nil }
shared_examples_for 'any platform' do
context 'the default action (:install)' do
context 'a custom source' do
let(:source) { 'https://example.biz.cdk' }
context 'an overridden channel property' do
let(:channel) { :current }
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
context 'an overridden version property' do
let(:version) { '4.5.6' }
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
end
context 'the :upgrade action' do
let(:action) { :upgrade }
context 'a custom source' do
let(:source) { 'https://example.biz.cdk' }
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
context 'an overridden version property' do
let(:version) { '1.2.3' }
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
end
shared_context 'the default action (:install)' do
before(:each) do
allow(Kernel).to receive(:load).and_call_original
allow(Kernel).to receive(:load)
.with(%r{chef-dk/libraries/helpers\.rb}).and_return(true)
allow(ChefDk::Helpers).to receive(:metadata_for).with(
channel: channel || :stable,
version: version || 'latest',
platform: platform,
platform_version: /#{platform_version}.*/,
machine: 'x86_64'
).and_return(
sha1: 'abcd',
sha256: '1234',
url: "http://example.com/#{channel || 'stable'}/chefdk",
version: version || '1.2.3'
)
end
end
shared_context 'the :upgrade action' do
let(:action) { :upgrade }
before(:each) do
allow(Kernel).to receive(:load).and_call_original
allow(Kernel).to receive(:load)
.with(%r{chef-dk/libraries/helpers\.rb}).and_return(true)
allow(ChefDk::Helpers).to receive(:metadata_for).with(
channel: channel || :stable,
version: version || 'latest',
platform: platform,
platform_version: /#{platform_version}.*/,
machine: 'x86_64'
).and_return(
sha1: 'abcd',
sha256: '1234',
url: "http://example.com/#{channel || 'stable'}/chefdk",
version: version || '1.2.3'
)
end
end
shared_context 'the :remove action' do
let(:action) { :remove }
end
shared_context 'the default source (:direct)' do
let(:source) { nil }
end
shared_context 'the :repo source' do
let(:source) { :repo }
end
shared_context 'a custom source' do
let(:source) { 'https://example.biz/cdk' }
let(:checksum) { '12345' }
end
shared_context 'all default properties' do
end
shared_context 'an overridden channel property' do
let(:channel) { :current }
end
shared_context 'an overridden version property' do
let(:version) { '4.5.6' }
end
shared_context 'the latest version already installed' do
let(:installed_version) { '1.2.3' }
end
shared_context 'an older version already installed' do
let(:installed_version) { '0.1.2' }
end
end