From 68328b6e15a38a74261ee46b06091b8e63f85499 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 9 Dec 2013 23:06:19 -0800 Subject: added initial white-box tests for couchdb and webapp nodes --- tests/README.md | 12 +++++++++++ tests/dummy.rb | 44 ------------------------------------- tests/network.rb | 12 ----------- tests/webapp.rb | 13 ----------- tests/white-box/couchdb.rb | 54 ++++++++++++++++++++++++++++++++++++++++++++++ tests/white-box/dummy.rb | 44 +++++++++++++++++++++++++++++++++++++ tests/white-box/network.rb | 13 +++++++++++ tests/white-box/webapp.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 176 insertions(+), 69 deletions(-) create mode 100644 tests/README.md delete mode 100644 tests/dummy.rb delete mode 100644 tests/network.rb delete mode 100644 tests/webapp.rb create mode 100644 tests/white-box/couchdb.rb create mode 100644 tests/white-box/dummy.rb create mode 100644 tests/white-box/network.rb create mode 100644 tests/white-box/webapp.rb (limited to 'tests') 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/dummy.rb b/tests/dummy.rb deleted file mode 100644 index e7964a6c..00000000 --- a/tests/dummy.rb +++ /dev/null @@ -1,44 +0,0 @@ -# only run in the dummy case where there is no hiera.yaml file. -raise SkipTest unless $node["dummy"] - -class Robot - def can_shoot_lasers? - "OHAI!" - end - - def can_fly? - "YES!" - end -end - -class TestDummy < LeapTest - def setup - @robot = Robot.new - end - - def test_lasers - assert_equal "OHAI!", @robot.can_shoot_lasers? - pass - end - - def test_fly - refute_match /^no/i, @robot.can_fly? - pass - end - - def test_blah - assert false - pass - end - - def test_that_will_be_skipped - skip "test this later" - pass - end - - def test_err - 12/0 - pass - end - -end 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/white-box/dummy.rb b/tests/white-box/dummy.rb new file mode 100644 index 00000000..dd343769 --- /dev/null +++ b/tests/white-box/dummy.rb @@ -0,0 +1,44 @@ +# only run in the dummy case where there is no hiera.yaml file. +raise SkipTest unless $node["dummy"] + +class Robot + def can_shoot_lasers? + "OHAI!" + end + + def can_fly? + "YES!" + end +end + +class TestDummy < LeapTest + def setup + @robot = Robot.new + end + + def test_lasers + assert_equal "OHAI!", @robot.can_shoot_lasers? + pass + end + + def test_fly + refute_match /^no/i, @robot.can_fly? + pass + end + + def test_blah + fail "blah" #assert false + pass + end + + def test_01_will_be_skipped + skip "test this later" + pass + end + + def test_err + 12/0 + pass + end + +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 -- cgit v1.2.3