ref: refs/heads/master
commit b1d894c4dbcc4a9ea1f45e2a365616cbfae58adb
Author: Duncan Mac-Vicar P
Date: Thu Feb 5 18:45:10 2009 +0100
add url() to webserver so we can detect hostname and jump over the ipv6
breakage when using localhost
---
tests/lib/WebServer.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
tests/lib/WebServer.h | 11 +++++++++++
tests/zypp/Fetcher_test.cc | 4 ++--
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/tests/lib/WebServer.cc b/tests/lib/WebServer.cc
index 426b08e..15d9430 100644
--- a/tests/lib/WebServer.cc
+++ b/tests/lib/WebServer.cc
@@ -14,6 +14,17 @@
using namespace zypp;
using namespace std;
+static inline string hostname()
+{
+ static char buf[256];
+ string result;
+ if (!::gethostname(buf, 255))
+ result += string(buf);
+ else
+ return "localhost";
+ return result;
+}
+
#define WEBRICK 1
class WebServer::Impl
@@ -36,6 +47,13 @@ public:
virtual void worker_thread()
{}
+
+ virtual int port() const
+ {
+ return 0;
+ }
+
+
private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
@@ -57,6 +75,12 @@ public:
if ( ! _stopped )
stop();
}
+
+ virtual int port() const
+ {
+ return _port;
+ }
+
virtual void worker_thread()
{
@@ -145,6 +169,12 @@ public:
mg_set_option(_ctx, "root", _docroot.c_str());
_stopped = false;
}
+
+ virtual int port() const
+ {
+ return _port;
+ }
+
virtual string log() const
{
@@ -188,6 +218,20 @@ std::string WebServer::log() const
return _pimpl->log();
}
+int WebServer::port() const
+{
+ return _pimpl->port();
+}
+
+
+Url WebServer::url() const
+{
+ Url url;
+ url.setHost(hostname());
+ url.setPort(str::numstring(port()));
+ url.setScheme("http");
+ return url;
+}
void WebServer::stop()
{
diff --git a/tests/lib/WebServer.h b/tests/lib/WebServer.h
index e7c5420..ec62e41 100644
--- a/tests/lib/WebServer.h
+++ b/tests/lib/WebServer.h
@@ -5,6 +5,7 @@
#include "boost/thread.hpp"
#include "boost/smart_ptr.hpp"
+#include "zypp/Url.h"
#include "zypp/Pathname.h"
#include "zypp/base/PtrTypes.h"
@@ -48,6 +49,16 @@ class WebServer
* Stops the worker thread
*/
void stop();
+
+ /**
+ * returns the port we are listening to
+ */
+ int port() const;
+
+ /**
+ * returns the base url where the webserver is listening
+ */
+ zypp::Url url() const;
/**
* shows the log of last run
diff --git a/tests/zypp/Fetcher_test.cc b/tests/zypp/Fetcher_test.cc
index c663c11..c7af0a4 100644
--- a/tests/zypp/Fetcher_test.cc
+++ b/tests/zypp/Fetcher_test.cc
@@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http)
WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str(), 10001);
web.start();
- MediaSetAccess media( Url("http://localhost:10001"), "/" );
+ MediaSetAccess media( web.url(), "/" );
Fetcher fetcher;
filesystem::TmpDir dest;
@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() , 10001 );
web.start();
- MediaSetAccess media( Url("http://localhost:10001"), "/" );
+ MediaSetAccess media( web.url(), "/" );
Fetcher fetcher;
filesystem::TmpDir dest;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org