diff options
Diffstat (limited to 'tests/white-box')
-rw-r--r-- | tests/white-box/couchdb.rb | 54 | ||||
-rw-r--r-- | tests/white-box/dummy.rb | 44 | ||||
-rw-r--r-- | tests/white-box/network.rb | 13 | ||||
-rw-r--r-- | tests/white-box/webapp.rb | 53 |
4 files changed, 164 insertions, 0 deletions
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 |