2016-02-10 00:58:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
2016-02-11 12:53:42 +01:00
|
|
|
#include "cpp-utils/network/FakeHttpClient.h"
|
|
|
|
#include "cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h"
|
2015-11-24 07:47:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
using namespace cpputils;
|
|
|
|
|
|
|
|
TEST(FakeHttpClientTest, Empty) {
|
2018-09-17 08:37:12 +02:00
|
|
|
EXPECT_ANY_THROW(FakeHttpClient().get("http://example.com"));
|
2015-11-24 07:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FakeHttpClientTest, Nonexisting) {
|
|
|
|
FakeHttpClient client;
|
|
|
|
client.addWebsite("http://existing.com", "content");
|
2018-09-17 08:37:12 +02:00
|
|
|
EXPECT_ANY_THROW(client.get("http://notexisting.com"));
|
2015-11-24 07:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FakeHttpClientTest, Existing) {
|
|
|
|
FakeHttpClient client;
|
|
|
|
client.addWebsite("http://existing.com", "content");
|
2018-09-17 08:37:12 +02:00
|
|
|
EXPECT_EQ("content", client.get("http://existing.com"));
|
2015-11-24 07:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FakeHttpClientTest, TwoExisting) {
|
|
|
|
FakeHttpClient client;
|
|
|
|
client.addWebsite("http://firstexisting.com", "first_content");
|
|
|
|
client.addWebsite("http://secondexisting.com", "second_content");
|
2018-09-17 08:37:12 +02:00
|
|
|
EXPECT_EQ("first_content", client.get("http://firstexisting.com"));
|
|
|
|
EXPECT_EQ("second_content", client.get("http://secondexisting.com"));
|
|
|
|
EXPECT_ANY_THROW(client.get("http://notexisting.com"));
|
2015-11-24 07:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FakeHttpClientTest, Overwriting) {
|
|
|
|
FakeHttpClient client;
|
|
|
|
client.addWebsite("http://existing.com", "content");
|
|
|
|
client.addWebsite("http://existing.com", "new_content");
|
2018-09-17 08:37:12 +02:00
|
|
|
EXPECT_EQ("new_content", client.get("http://existing.com"));
|
2015-11-24 07:47:29 +01:00
|
|
|
}
|