Skip to content

Commit

Permalink
etcd: add test
Browse files Browse the repository at this point in the history
This test starts an etcd process as a single-node cluster, stores a test
string in the key-value store, retrieves it, and compares it against the
original string. This tests whether etcd can start properly, select
itself as a leader, accept a PUT request, store the value, then return
it on a GET. We kill the etcd process once we are done.

Closes Homebrew/legacy-homebrew#39095.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
  • Loading branch information
JasonBoyles authored and MikeMcQuaid committed Apr 27, 2015
1 parent e01689d commit f475e6d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Formula/etcd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ def install
bin.install "bin/etcdctl"
end

test do
begin
require "utils/json"
test_string = "Hello from brew test!"
etcd_pid = fork do
exec "etcd", "--force-new-cluster", "--data-dir=#{testpath}"
end
# sleep to let etcd get its wits about it
sleep 10
etcd_uri = "http://127.0.0.1:4001/v2/keys/brew_test"
system "curl", "--silent", "-L", etcd_uri, "-XPUT", "-d", "value=#{test_string}"
curl_output = shell_output "curl --silent -L #{etcd_uri}"
response_hash = Utils::JSON.load(curl_output)
assert_match(test_string, response_hash.fetch("node").fetch("value"))
ensure
# clean up the etcd process before we leave
Process.kill("HUP", etcd_pid)
end
end

def plist; <<-EOS.undent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Expand Down

0 comments on commit f475e6d

Please sign in to comment.