Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

fix guard and update monit binary version #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions recipes/install_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"cd #{File.basename(tar_file, ".tar.gz")}",
"cp bin/monit #{node["monit"]["binary"]["prefix"]}/bin/monit"
].join(" && ")
not_if { ::File.exist?(binary) }
not_if "monit -V | grep #{node["monit"]["binary"]["version"]}"
action :nothing
end

Expand Down
18 changes: 9 additions & 9 deletions spec/install_binary_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require "spec_helper"

describe "monit::install_binary" do
let(:monit_tarball) { "/var/chef/cache/monit-5.12.2.tar.gz" }
let(:monit_tarball) { "/var/chef/cache/monit-5.13.tar.gz" }

let(:install_binary_command) do
"tar zxvf monit-5.12.2.tar.gz && cd monit-5.12.2 && cp bin/monit /usr/bin/monit" # rubocop:disable Metrics/LineLength
"tar zxvf monit-5.13.tar.gz && cd monit-5.13 && cp bin/monit /usr/bin/monit" # rubocop:disable Metrics/LineLength
end

describe "when binary is not found" do
let(:chef_run) do
ChefSpec::SoloRunner.new(file_cache_path: "/var/chef/cache") do |node|
node.set["monit"]["binary"]["version"] = "5.12.2"
node.set["monit"]["binary"]["version"] = "5.13"
node.set["monit"]["binary"]["prefix"] = "/usr"
end.converge(described_recipe)
end
Expand All @@ -37,7 +37,7 @@
describe "when binary is found and installing a different version" do
let(:chef_run) do
ChefSpec::SoloRunner.new(file_cache_path: "/var/chef/cache") do |node|
node.set["monit"]["binary"]["version"] = "5.12.2"
node.set["monit"]["binary"]["version"] = "5.13"
node.set["monit"]["binary"]["prefix"] = "/usr"
end.converge(described_recipe)
end
Expand All @@ -46,8 +46,8 @@
allow(::File).to receive(:exist?).and_call_original
allow(::File).to receive(:exist?).with("/usr/bin/monit").and_return(true)

# example: 5.12.1 was installed
stub_command("monit -V | grep 5.12.2").and_return(false)
# example: 5.12.2 was installed
stub_command("monit -V | grep 5.13").and_return(false)

expect(chef_run).to run_execute("rm /usr/bin/monit")
remove_existing_binary = chef_run.execute("rm /usr/bin/monit")
Expand Down Expand Up @@ -77,17 +77,17 @@
describe "when binary is found and installing the same version" do
let(:chef_run) do
ChefSpec::SoloRunner.new(file_cache_path: "/var/chef/cache") do |node|
node.set["monit"]["binary"]["version"] = "5.12.2"
node.set["monit"]["binary"]["version"] = "5.13"
node.set["monit"]["binary"]["prefix"] = "/usr"
end.converge(described_recipe)
end

specify do
allow(::File).to receive(:exist?).and_call_original
allow(::File).to receive(:exist?).with("/usr/bin/monit").and_return(true)
stub_command("monit -V | grep 5.12.2").and_return(true)
stub_command("monit -V | grep 5.13").and_return(true)

expect(chef_run).not_to run_execute("rm /usr/bin/monit")
expect(chef_run).to_not run_execute("rm /usr/bin/monit")

expect(chef_run).to_not(
run_execute("install-monit-binary").with(
Expand Down