Skip to content

Commit

Permalink
Test that the key is the one we expect
Browse files Browse the repository at this point in the history
In the Redis healthcheck we write and read to a key, so we should check
it's doing that to the key we want it to. This also opens up the
potential for having different keys.
  • Loading branch information
thomasleese committed Jan 18, 2021
1 parent 24dd408 commit c9d0e9b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spec/lib/govuk_healthcheck/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@
end

context "when the database is connected" do
before { allow(redis_client).to receive(:set) }
before do
allow(redis_client)
.to receive(:set).with("healthcheck", anything)
end

it_behaves_like "a healthcheck"

it "returns OK" do
expect(redis_client).to receive(:set).with(anything, anything)
expect(subject.status).to eq(GovukHealthcheck::OK)
end
end

context "when the database is not connected" do
before { allow(redis_client).to receive(:set).with(anything, anything).and_raise("error") }
before do
allow(redis_client)
.to receive(:set).with("healthcheck", anything)
.and_raise("error")
end

it_behaves_like "a healthcheck"

it "returns CRITICAL" do
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
end
Expand Down

0 comments on commit c9d0e9b

Please sign in to comment.