diff --git a/core/src/CurlHttpClient.h b/core/src/CurlHttpClient.h index 4480419b7..9c08c3e6e 100644 --- a/core/src/CurlHttpClient.h +++ b/core/src/CurlHttpClient.h @@ -1,12 +1,12 @@ /* * Copyright 2009-2017 Alibaba Cloud All rights reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 09f867667..86bf04df0 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -38,6 +38,7 @@ include_directories("../../core/include/") add_executable(core_ut alibabacloud_ut.cc asynccallercontext_ut.cc + coreclient_ut.cc clientconfiguration_ut.cc commonclient_ut.cc commonrequest_ut.cc diff --git a/test/core/coreclient_ut.cc b/test/core/coreclient_ut.cc new file mode 100644 index 000000000..c43f56e00 --- /dev/null +++ b/test/core/coreclient_ut.cc @@ -0,0 +1,44 @@ + +#include +#include +#include "gtest/gtest.h" +#include "alibabacloud/core/CoreClient.h" + +using namespace std; +using namespace AlibabaCloud; + +namespace AlibabaCloud { + class TestCoreClient : public CoreClient { + public: + TestCoreClient(const std::string & servicename, const ClientConfiguration &configuration): + CoreClient(servicename, configuration) + {} + + using CoreClient::buildCoreError; + using CoreClient::hasResponseError; + HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const { + Url url; + url.setScheme("abc"); + url.setUserName("username"); + HttpRequest req(url, HttpRequest::Method::Post); + return req; + } + }; +} + + +TEST(CoreClient, basic) { + ClientConfiguration configuration; + TestCoreClient client("test-service", configuration); + + HttpResponse res; + Error e1 = client.buildCoreError(res); + EXPECT_TRUE(e1.errorCode() == ("InvalidResponse")); + string body = "{\"Code\":\"any-error-code\",\"Message\":\"any-error-message\",\"HostId\":\"any-host-id\",\"RequestId\":\"any-request-id\"}"; + res.setBody(body.c_str(), body.size()); + Error e2 = client.buildCoreError(res); + EXPECT_TRUE(e2.errorCode() == ("any-error-code")); + EXPECT_TRUE(e2.errorMessage() == ("any-error-message")); + EXPECT_TRUE(e2.host() == ("any-host-id")); + EXPECT_TRUE(e2.requestId() == ("any-request-id")); +}