Sha256: e6b6d062071a0d732426deb28d088d29e868f92bb83c88963e752a4056845638

Contents?: true

Size: 1.93 KB

Versions: 14

Compression:

Stored size: 1.93 KB

Contents

#include <catch.hpp>
#include "mock_curl.hpp"
#include <leatherman/curl/client.hpp>
#include <leatherman/curl/request.hpp>

using namespace std;
using namespace leatherman::curl;

struct mock_client : client {
    curl_handle const& get_handle() { return client::get_handle(); }
};

TEST_CASE("curl::response") {
    response test_response;

    SECTION("Headers should be addable and retrievable from the response") {
        test_response.add_header("header_name", "header_value");
        auto header = test_response.header("header_name");
        REQUIRE(header);
        REQUIRE(*(header) == "header_value");
    }

    SECTION("Headers should be removable from the response") {
        test_response.add_header("header_name", "header_value");
        test_response.remove_header("header_name");
        auto header = test_response.header("header_name");
        REQUIRE(header == nullptr);
    }

    SECTION("Headers should be enumerable") {
        int i = 0;
        string expected_name, expected_value;
        test_response.add_header("header_0", "header_value_0");
        test_response.add_header("header_1", "header_value_1");
        test_response.add_header("header_2", "header_value_2");

        test_response.each_header([&](string const& name, string const& value) {
            expected_name  = "header_" + to_string(i);
            expected_value = "header_value_" + to_string(i);
            REQUIRE(name == expected_name);
            REQUIRE(value == expected_value);
            ++i;
            return true;
        });
    }

    SECTION("Response body should be addable and retrievable") {
        test_response.body("Hello, I am a response body!");
        auto body = test_response.body();
        REQUIRE(body == "Hello, I am a response body!");
    }

    SECTION("Status code should be addable and retrievable") {
        test_response.status_code(200);
        auto code = test_response.status_code();
        REQUIRE(code == 200);
    }
}

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/curl/tests/response_test.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/curl/tests/response_test.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/curl/tests/response_test.cc