summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-12-09 23:06:19 -0800
committerelijah <elijah@riseup.net>2013-12-09 23:06:19 -0800
commit68328b6e15a38a74261ee46b06091b8e63f85499 (patch)
treedc8328e92113d5ceaa4bbea00048eb8b13f65b80 /tests
parente23dc7849d1118ed2dfe7f37a6109ffbeefa959c (diff)
added initial white-box tests for couchdb and webapp nodes
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md12
-rw-r--r--tests/network.rb12
-rw-r--r--tests/webapp.rb13
-rw-r--r--tests/white-box/couchdb.rb54
-rw-r--r--tests/white-box/dummy.rb (renamed from tests/dummy.rb)4
-rw-r--r--tests/white-box/network.rb13
-rw-r--r--tests/white-box/webapp.rb53
7 files changed, 134 insertions, 27 deletions
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 00000000..debbf700
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,12 @@
+This directory contains to kinds of tests:
+
+White Box Tests
+================================
+
+These tests are run on the server as superuser. They are for troubleshooting any problems with the internal setup of the server.
+
+Black Box Tests
+================================
+
+These test are run the user's local machine. They are for troubleshooting any external problems with the service exposed by the server.
+
diff --git a/tests/network.rb b/tests/network.rb
deleted file mode 100644
index 115d356a..00000000
--- a/tests/network.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.dirname(__FILE__) + '/webapp'
-
-class TestNetwork < LeapTest
-
- def setup
- end
-
- def test_test
- pass
- end
-
-end
diff --git a/tests/webapp.rb b/tests/webapp.rb
deleted file mode 100644
index 1762de9e..00000000
--- a/tests/webapp.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-raise SkipTest unless $node["services"].include?("webapp")
-
-class TestAWebapp < LeapTest
- depends_on "TestNetwork"
-
- def setup
- end
-
- def test_test
- assert false, 'hey, stop here'
- end
-
-end
diff --git a/tests/white-box/couchdb.rb b/tests/white-box/couchdb.rb
new file mode 100644
index 00000000..0fc4d3b2
--- /dev/null
+++ b/tests/white-box/couchdb.rb
@@ -0,0 +1,54 @@
+raise SkipTest unless $node["services"].include?("couchdb")
+
+require 'json'
+
+class TestCouchdb < LeapTest
+
+ def setup
+ end
+
+ #
+ # check to make sure we can get welcome response from local couchdb
+ #
+ def test_01_is_running
+ assert_get(couchdb_url) do |body|
+ assert_match /"couchdb":"Welcome"/, body, "Could not get welcome message from #{couchdb_url}. Probably couchdb is not running."
+ end
+ pass
+ end
+
+ #
+ # compare the configured nodes to the nodes that are actually listed in bigcouch
+ #
+ def test_02_nodes_are_in_replication_database
+ url = couchdb_admin_url("/nodes/_all_docs")
+ neighbors = assert_property('couch.bigcouch.neighbors')
+ neighbors << assert_property('domain.full')
+ neighbors.sort!
+ assert_get(url) do |body|
+ response = JSON.parse(body)
+ nodes_in_db = response['rows'].collect{|row| row['id'].sub(/^bigcouch@/, '')}.sort
+ assert_equal neighbors, nodes_in_db, "The couchdb replication node list is wrong (/nodes/_all_docs)"
+ end
+ pass
+ end
+
+ private
+
+ def couchdb_url(path="", port=nil)
+ @port ||= begin
+ assert_property 'couch.port'
+ $node['couch']['port']
+ end
+ @password ||= begin
+ assert_property 'couch.users.admin.password'
+ $node['couch']['users']['admin']['password']
+ end
+ "http://admin:#{@password}@localhost:#{port || @port}#{path}"
+ end
+
+ def couchdb_admin_url(path="")
+ couchdb_url(path, "5986") # admin port is hardcoded for now.
+ end
+
+end
diff --git a/tests/dummy.rb b/tests/white-box/dummy.rb
index e7964a6c..dd343769 100644
--- a/tests/dummy.rb
+++ b/tests/white-box/dummy.rb
@@ -27,11 +27,11 @@ class TestDummy < LeapTest
end
def test_blah
- assert false
+ fail "blah" #assert false
pass
end
- def test_that_will_be_skipped
+ def test_01_will_be_skipped
skip "test this later"
pass
end
diff --git a/tests/white-box/network.rb b/tests/white-box/network.rb
new file mode 100644
index 00000000..9680cb5f
--- /dev/null
+++ b/tests/white-box/network.rb
@@ -0,0 +1,13 @@
+class TestNetwork < LeapTest
+
+ def setup
+ end
+
+ #
+ # TODO: write an actual test to confirm the network is up and working.
+ #
+ def test_working
+ pass
+ end
+
+end
diff --git a/tests/white-box/webapp.rb b/tests/white-box/webapp.rb
new file mode 100644
index 00000000..65f3217b
--- /dev/null
+++ b/tests/white-box/webapp.rb
@@ -0,0 +1,53 @@
+raise SkipTest unless $node["services"].include?("webapp")
+
+class TestWebapp < LeapTest
+ depends_on "TestNetwork"
+
+ HAPROXY_CONFIG = '/etc/haproxy/haproxy.cfg'
+
+ def setup
+ end
+
+ #
+ # example properties:
+ #
+ # stunnel:
+ # couch_client:
+ # couch1_5984:
+ # accept_port: 4000
+ # connect: couch1.bitmask.i
+ # connect_port: 15984
+ #
+ def test_01_stunnel_is_working
+ assert_property('stunnel.couch_client')
+ $node['stunnel']['couch_client'].values.each do |stunnel_conf|
+ assert port = stunnel_conf['accept_port'], 'Field `accept_port` must be present in `stunnel` property.'
+ local_stunnel_url = "http://localhost:#{port}"
+ assert_get(local_stunnel_url) do |body|
+ assert_match /"couchdb":"Welcome"/, body, "Request to #{local_stunnel_url} should return couchdb welcome message."
+ end
+ end
+ pass
+ end
+
+ #
+ # example properties:
+ #
+ # haproxy:
+ # servers:
+ # couch1:
+ # backup: false
+ # host: localhost
+ # port: 4000
+ # weight: 10
+ #
+ def test_02_haproxy_is_working
+ port = file_match(HAPROXY_CONFIG, /^ bind localhost:(\d+)$/)
+ url = "http://localhost:#{port}"
+ assert_get(url) do |body|
+ assert_match /"couchdb":"Welcome"/, body, "Request to #{url} should return couchdb welcome message."
+ end
+ pass
+ end
+
+end