Skip to content

Commit

Permalink
Add some basic cookie tests
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
whoshuu committed Jun 16, 2015
1 parent c0c39ce commit 78a1661
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/async_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cpr.h>

#include "cookies.h"
#include "multipart.h"
#include "server.h"
#include <iostream>
Expand Down Expand Up @@ -64,6 +65,37 @@ TEST(UrlEncodedPostTests, AsyncGetMultipleReflectTest) {
}
}

TEST(CookiesTests, CookiesTest) {
auto url = Url{base + "/basic_cookies.html"};
Session session{};
session.SetUrl(url);
Cookies cookies;

{
auto response = session.Get();
auto expected_text = std::string{"Hello world!"};
EXPECT_EQ(expected_text, response.text);
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(200, response.status_code);
cookies = response.cookies;
}
{
cookies["hello"] = "world";
cookies["my"] = "another; fake=cookie;"; // This is url encoded
session.SetCookies(cookies);
auto response = session.Get();
auto expected_text = std::string{"Hello world!"};
EXPECT_EQ(expected_text, response.text);
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(cookies["cookie"], response.cookies["cookie"]);
EXPECT_EQ(cookies["icecream"], response.cookies["icecream"]);
EXPECT_EQ(cookies["expires"], response.cookies["expires"]);
}
}

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(server);
Expand Down

0 comments on commit 78a1661

Please sign in to comment.