diff options
author | Ted Ross <tross@apache.org> | 2009-01-09 18:42:01 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2009-01-09 18:42:01 +0000 |
commit | feb2c38b24deb8fcacdb11cdd4920a61d0c88ee0 (patch) | |
tree | e08b7f99730023c734042560da7edb1234acf1b8 | |
parent | e8bc90906d322a676b931834a894d5c6bd2aa97e (diff) | |
download | qpid-python-feb2c38b24deb8fcacdb11cdd4920a61d0c88ee0.tar.gz |
Added test coverage for the CLI utilities
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@733108 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | cpp/src/tests/Makefile.am | 3 | ||||
-rwxr-xr-x | cpp/src/tests/cli_tests.py | 152 | ||||
-rwxr-xr-x | cpp/src/tests/run_cli_tests | 53 |
3 files changed, 207 insertions, 1 deletions
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 47439d0bab..8cc72da96b 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -198,7 +198,7 @@ DispatcherTest_LDADD=$(lib_common) TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) QPID_DATA_DIR= BOOST_TEST_SHOW_PROGRESS=yes $(srcdir)/run_test system_tests = client_test quick_perftest quick_topictest run_header_test quick_txtest -TESTS += start_broker $(system_tests) python_tests stop_broker run_federation_tests run_acl_tests +TESTS += start_broker $(system_tests) python_tests stop_broker run_federation_tests run_acl_tests run_cli_tests EXTRA_DIST += \ run_test vg_check \ @@ -213,6 +213,7 @@ EXTRA_DIST += \ config.null \ ais_check \ run_federation_tests \ + run_cli_tests \ run_acl_tests \ .valgrind.supp \ MessageUtils.h \ diff --git a/cpp/src/tests/cli_tests.py b/cpp/src/tests/cli_tests.py new file mode 100755 index 0000000000..93d960cb5b --- /dev/null +++ b/cpp/src/tests/cli_tests.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import sys +import os +from qpid.testlib import TestBase010, testrunner +from qpid.datatypes import Message +from qpid.queue import Empty +from time import sleep + +def add_module(args=sys.argv[1:]): + for a in args: + if a.startswith("cli"): + return False + return True + +def scan_args(name, default=None, args=sys.argv[1:]): + if (name in args): + pos = args.index(name) + return args[pos + 1] + elif default: + return default + else: + print "Please specify extra argument: %s" % name + sys.exit(2) + +def extract_args(name, args): + if (name in args): + pos = args.index(name) + del args[pos:pos+2] + else: + return None + +def remote_host(): + return scan_args("--remote-host", "localhost") + +def remote_port(): + return int(scan_args("--remote-port")) + +def cli_dir(): + return scan_args("--cli-dir") + +class CliTests(TestBase010): + + def test_qpid_config(self): + self.startQmf(); + qmf = self.qmf + qname = "test_qpid_config" + + ret = os.system(self.command(" add queue " + qname)) + self.assertEqual(ret, 0) + queues = qmf.getObjects(_class="queue") + found = False + for queue in queues: + if queue.name == qname: + self.assertEqual(queue.durable, False) + found = True + self.assertEqual(found, True) + + ret = os.system(self.command(" del queue " + qname)) + self.assertEqual(ret, 0) + queues = qmf.getObjects(_class="queue") + found = False + for queue in queues: + if queue.name == qname: + found = True + self.assertEqual(found, False) + + def test_qpid_config_durable(self): + self.startQmf(); + qmf = self.qmf + qname = "test_qpid_config" + + ret = os.system(self.command(" add queue --durable " + qname)) + self.assertEqual(ret, 0) + queues = qmf.getObjects(_class="queue") + found = False + for queue in queues: + if queue.name == qname: + self.assertEqual(queue.durable, True) + found = True + self.assertEqual(found, True) + + ret = os.system(self.command(" del queue " + qname)) + self.assertEqual(ret, 0) + queues = qmf.getObjects(_class="queue") + found = False + for queue in queues: + if queue.name == qname: + found = True + self.assertEqual(found, False) + + def test_qpid_route(self): + self.startQmf(); + qmf = self.qmf + + command = cli_dir() + "/qpid-route dynamic add localhost:%d %s:%d amq.topic" %\ + (testrunner.port, remote_host(), remote_port()) + ret = os.system(command) + self.assertEqual(ret, 0) + + links = qmf.getObjects(_class="link") + found = False + for link in links: + if link.port == remote_port(): + found = True + self.assertEqual(found, True) + + def getProperty(self, msg, name): + for h in msg.headers: + if hasattr(h, name): return getattr(h, name) + return None + + def getAppHeader(self, msg, name): + headers = self.getProperty(msg, "application_headers") + if headers: + return headers[name] + return None + + def command(self, arg = ""): + return cli_dir() + "/qpid-config -a localhost:%d" % testrunner.port + " " + arg + + +if __name__ == '__main__': + args = sys.argv[1:] + #need to remove the extra options from args as test runner doesn't recognise them + extract_args("--remote-port", args) + extract_args("--remote-host", args) + extract_args("--cli-dir", args) + + if add_module(): + #add module(s) to run to testrunners args + args.append("cli_tests") + + if not testrunner.run(args): sys.exit(1) diff --git a/cpp/src/tests/run_cli_tests b/cpp/src/tests/run_cli_tests new file mode 100755 index 0000000000..3d1d1e2868 --- /dev/null +++ b/cpp/src/tests/run_cli_tests @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Run the cli-utility tests. +MY_DIR=`dirname \`which $0\`` +PYTHON_DIR=${MY_DIR}/../../../python +CLI_DIR=${PYTHON_DIR}/commands + +trap stop_brokers INT TERM QUIT + +start_brokers() { + ../qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no > qpidd.port + LOCAL_PORT=`cat qpidd.port` + ../qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no > qpidd.port + REMOTE_PORT=`cat qpidd.port` +} + +stop_brokers() { + ../qpidd -q --port $LOCAL_PORT + ../qpidd -q --port $REMOTE_PORT +} + +if test -d ${PYTHON_DIR} ; then + start_brokers + echo "Running CLI tests using brokers on ports $LOCAL_PORT $REMOTE_PORT" + PYTHONPATH=${PYTHON_DIR} + export PYTHONPATH + ${MY_DIR}/cli_tests.py -v -s ${MY_DIR}/../../../specs/amqp.0-10-qpid-errata.xml -b localhost:$LOCAL_PORT --remote-port $REMOTE_PORT --cli-dir $CLI_DIR $@ + RETCODE=$? + stop_brokers + if test x$RETCODE != x0; then + echo "FAIL CLI tests"; exit 1; + fi +fi + |