unit test for coreclient

This commit is contained in:
zhangzifa
2019-01-23 14:55:15 +08:00
committed by Jackson Tian
parent e00a04b071
commit e477d06dea
3 changed files with 48 additions and 3 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -0,0 +1,44 @@
#include <iostream>
#include <stdio.h>
#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"));
}