File: CurlHttpClientTest.cpp

package info (click to toggle)
cryfs 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,404 kB
  • sloc: cpp: 150,188; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (38 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "cpp-utils/network/CurlHttpClient.h"
#include "cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h"

using std::string;

using namespace cpputils;

// Disable these by default because they depend on network
// and - even if network is available - can fail depending
// on the concrete network setup (e.g. if invalid domains are
// answered with an ISP page instead of HTTP error)
#ifdef CRYFS_ENABLE_NETWORK_TESTS

TEST(CurlHttpClientTest, InvalidProtocol) {
    EXPECT_EQ(none, CurlHttpClient().get("invalid://example.com"));
}

TEST(CurlHttpClientTest, InvalidTld) {
    EXPECT_EQ(none, CurlHttpClient().get("http://example.invalidtld"));
}

TEST(CurlHttpClientTest, InvalidDomain) {
    EXPECT_EQ(none, CurlHttpClient().get("http://this_is_a_not_existing_domain.com"));
}

TEST(CurlHttpClientTest, ValidHttp) {
    string content = CurlHttpClient().get("http://example.com").value();
    EXPECT_THAT(content, MatchesRegex(".*Example Domain.*"));
}

TEST(CurlHttpClientTest, ValidHttps) {
    string content = CurlHttpClient().get("https://example.com").value();
    EXPECT_THAT(content, MatchesRegex(".*Example Domain.*"));
}

#endif