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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#
# Copyright:: Copyright (c) 2015-2018 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"
require "mixlib/install"
context "Mixlib::Install" do
let(:installer) do
Mixlib::Install.new(
product_name: product_name,
channel: channel,
product_version: product_version,
platform: platform,
platform_version: platform_version,
architecture: architecture
)
end
let(:channel) { :stable }
let(:product_version) { :latest }
let(:platform) { nil }
let(:platform_version) { nil }
let(:architecture) { nil }
context "querying current version" do
let(:version_manifest_file) { "/opt/#{product_name}/version-manifest.json" }
context "when products are installed" do
before do
expect(File).to receive(:exist?).with(version_manifest_file).and_return(true)
expect(File).to receive(:read).with(version_manifest_file).and_wrap_original do |m, path|
m.call(File.join(VERSION_MANIFEST_DIR, path))
end
end
context "with product name chef" do
let(:product_name) { "chef" }
it "should report version correctly" do
expect(installer.current_version).to eq("12.4.3")
end
end
context "with product name chef" do
let(:product_name) { "chefdk" }
it "should report version correctly" do
expect(installer.current_version).to eq("0.7.0")
end
end
end
context "when product is not installed" do
let(:product_name) { "chef" }
before do
expect(File).to receive(:exist?).with(version_manifest_file).and_return(false)
end
it "should report version as nil" do
expect(installer.current_version).to eq(nil)
end
end
end
context "checking for upgrades", :vcr do
before do
allow(installer).to receive(:current_version).and_return(current_version)
end
context "with nil as current_version" do
let(:product_name) { "chefdk" }
let(:channel) { :stable }
let(:product_version) { :latest }
let(:current_version) { nil }
it "should report upgrade available" do
expect(installer.upgrade_available?).to eq(true)
end
end
context "with :latest, upgrade exists, :stable channel" do
let(:product_name) { "chefdk" }
let(:channel) { :stable }
let(:product_version) { :latest }
let(:current_version) { "0.4.0" }
it "should report upgrade available" do
expect(installer.upgrade_available?).to eq(true)
end
end
context "with specific version lower than current, :stable channel" do
let(:product_name) { "chefdk" }
let(:channel) { :stable }
let(:product_version) { "0.3.0" }
let(:current_version) { "0.4.0" }
it "should report upgrade available" do
expect(installer.upgrade_available?).to eq(false)
end
end
context "with specific version higher than current, :stable channel" do
let(:product_name) { "chefdk" }
let(:channel) { :stable }
let(:product_version) { "0.7.0" }
let(:current_version) { "0.4.0" }
it "should report upgrade available" do
expect(installer.upgrade_available?).to eq(true)
end
end
context "with specific platform options" do
let(:product_name) { "chefdk" }
let(:platform) { "ubuntu" }
let(:platform_version) { "14.04" }
let(:architecture) { "x86_64" }
let(:current_version) { nil }
it "should report upgrade available" do
expect(installer.upgrade_available?).to eq(true)
end
end
end
context "install_sh" do
let(:base_url) { nil }
let(:install_sh) do
options = {}.tap do |opt|
opt[:base_url] = base_url if base_url
end
Mixlib::Install.install_sh(options)
end
it "should render a script with cli parameters" do
expect(install_sh).to include("while getopts pnv:c:f:P:d:s:l:a opt")
end
context "with custom base_url" do
let(:base_url) { "https://my.omnitruck.com/" }
it "should render with the given base_url" do
expect(install_sh).to include(base_url)
end
end
it "should render with default base_url if one is not given" do
expect(install_sh).to include("https://omnitruck.chef.io")
end
end
context "install_ps1" do
let(:base_url) { nil }
let(:install_ps1) do
options = {}.tap do |opt|
opt[:base_url] = base_url if base_url
end
Mixlib::Install.install_ps1(options)
end
it "should render a script with cli & backcompat parameters" do
expect(install_ps1).not_to include("install -project")
expect(install_ps1).to include("Get-ProjectMetadata -project $project -channel $channel -version $version -prerelease:$prerelease -nightlies:$nightlies")
end
context "with custom base_url" do
let(:base_url) { "https://my.omnitruck.com/" }
it "should render with the given base_url" do
expect(install_ps1).to include(base_url)
end
end
it "should render with default base_url if one is not given" do
expect(install_ps1).to include("https://omnitruck.chef.io")
end
end
context "self.detect_platform" do
let(:product_name) { "chef" }
let(:platform_info) { Mixlib::Install.detect_platform }
it "should return platform info" do
expect(platform_info.size).to eq 3
expect(installer.options.platform).to be_nil
expect(installer.options.platform_version).to be_nil
expect(installer.options.architecture).to be_nil
end
end
context "detect_platform" do
let(:product_name) { "chef" }
it "should set options" do
installer.detect_platform
expect(installer.options.platform).not_to be_nil
expect(installer.options.platform_version).not_to be_nil
expect(installer.options.architecture).not_to be_nil
end
end
context "detect_platform_sh" do
let(:script) { Mixlib::Install.detect_platform_sh }
it "should return platform_detection.sh" do
expect(script).to include('echo "$platform $platform_version $machine"')
end
it "should return platform_detection.sh using grep without -q" do
expect(script).not_to include("grep.*-q")
end
end
context "detect_platform_ps1" do
let(:script) { Mixlib::Install.detect_platform_ps1 }
it "should return platform_detection.ps1" do
expect(script).to include('Write-Host "windows $platform_version $architecture"')
end
end
context "available_versions", :vcr do
let(:product_name) { "chef" }
let(:channel) { :stable }
shared_examples_for "the correct available_versions" do
it "is an Array" do
expect(versions).to be_a Array
end
it "has expected version" do
expect(versions).to include "12.0.3"
end
end
context "when called as instance method" do
let(:versions) { installer.available_versions }
it_behaves_like "the correct available_versions"
end
context "when called static" do
let(:versions) { Mixlib::Install.available_versions(product_name, channel.to_s) }
it_behaves_like "the correct available_versions"
end
end
describe "#download_artifact" do
let(:product_name) { "chefdk" }
context "when platform options are not set" do
it "will raise an error" do
expect { installer.download_artifact }.to raise_error /Must provide platform options to download a specific artifact/
end
end
end
end
|