unit test for coreclient
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
44
test/core/coreclient_ut.cc
Normal file
44
test/core/coreclient_ut.cc
Normal 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"));
|
||||
}
|
||||
Reference in New Issue
Block a user