diff options
| -rw-r--r-- | tests/helpers/couchdb_helper.rb | 1 | ||||
| -rw-r--r-- | tests/helpers/http_helper.rb | 5 | ||||
| -rw-r--r-- | tests/white-box/couchdb.rb | 2 | ||||
| -rw-r--r-- | tests/white-box/mx.rb | 31 | 
4 files changed, 36 insertions, 3 deletions
| diff --git a/tests/helpers/couchdb_helper.rb b/tests/helpers/couchdb_helper.rb index d4d3c0e0..312e38ac 100644 --- a/tests/helpers/couchdb_helper.rb +++ b/tests/helpers/couchdb_helper.rb @@ -66,6 +66,7 @@ class LeapTest    #   port: 5984    #    def couchdb_url_via_localhost(path="", options=nil) +    path = path.gsub('"', '%22')      port = (options && options[:port]) || assert_property('couch.port')      if options && options[:username]        password = property("couch.users.%{username}.password" % options) diff --git a/tests/helpers/http_helper.rb b/tests/helpers/http_helper.rb index 0b13b754..2fcdc910 100644 --- a/tests/helpers/http_helper.rb +++ b/tests/helpers/http_helper.rb @@ -87,12 +87,13 @@ class LeapTest      options ||= {}      error_msg = options[:error_msg] || (url.respond_to?(:memo) ? url.memo : nil)      http_send(method, url, params, options) do |body, response, error| -      if body && response && response.code.to_i >= 200 && response.code.to_i < 300 +      ok = response && response.code.to_i >= 200 && response.code.to_i < 300 +      if body && ok          if block            yield(body) if block.arity == 1            yield(response, body) if block.arity == 2          end -      elsif response +      elsif response && !ok          fail ["Expected a 200 status code from #{method} #{url}, but got #{response.code} instead.", error_msg, body].compact.join("\n")        else          fail ["Expected a response from #{method} #{url}, but got \"#{error}\" instead.", error_msg, body].compact.join("\n"), error diff --git a/tests/white-box/couchdb.rb b/tests/white-box/couchdb.rb index edb28eac..da226cc9 100644 --- a/tests/white-box/couchdb.rb +++ b/tests/white-box/couchdb.rb @@ -9,8 +9,8 @@ class CouchDB < LeapTest    end    def test_00_Are_daemons_running? +    assert_running 'bin/beam'      if multimaster? -      assert_running 'bin/beam'        assert_running 'bin/epmd'      end      pass diff --git a/tests/white-box/mx.rb b/tests/white-box/mx.rb index ed990a2e..768b561f 100644 --- a/tests/white-box/mx.rb +++ b/tests/white-box/mx.rb @@ -31,6 +31,37 @@ class Mx < LeapTest      end    end +  # +  # this test picks a random identity document, then queries +  # using the by_address view for that same document again. +  # +  def test_03_Can_query_identities_db? +    assert_get(couchdb_url("/identities", url_options)) do |body| +      assert response = JSON.parse(body) +      doc_count = response['doc_count'].to_i +      if doc_count < 1 +        skip "There are no identity records yet." +      else +        offset = rand(doc_count) # pick a random document +        count_url = couchdb_url("/identities/_all_docs?include_docs=true&limit=1&skip=#{offset}", url_options) +        assert_get(count_url) do |body| +          assert response = JSON.parse(body) +          record = response['rows'].first +          address = record['doc']['address'] +          assert address, "address should not be empty" +          url_base = %(/identities/_design/Identity/_view/by_address) +          params = %(?include_docs=true&reduce=false&startkey="#{address}"&endkey="#{address}") +          assert_get(couchdb_url(url_base+params, url_options)) do |body| +            assert response = JSON.parse(body) +            assert record = response['rows'].first +            assert_equal address, record['doc']['address'] +            pass +          end +        end +      end +    end +  end +    def test_03_Are_MX_daemons_running?      assert_running '.*/usr/bin/twistd.*mx.tac'      assert_running '^/usr/lib/postfix/master$' | 
