client_configuration_provider_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
19 
20 using namespace Aws::Client;
21 using ::testing::_;
22 using ::testing::Matcher;
23 using ::testing::DoAll;
24 using ::testing::SetArgReferee;
25 using ::testing::Return;
26 using Aws::AwsError;
27 
28 class ClientConfigurationProviderFixture : public ::testing::Test
29 {
30 protected:
31  std::shared_ptr<ParameterReaderMock> param_reader_ =
32  std::make_shared<ParameterReaderMock>();
33  std::shared_ptr<ClientConfigurationProvider> test_subject_ =
34  std::make_shared<ClientConfigurationProvider>(param_reader_);
35 };
36 
38 {
39  const char* expected_str = "N2IxYjk2ZDhkYTNmZWQ2ZjkwMDlhNWRl";
40  const int kExpectedInt = 64654;
41  const bool kExpectedBool = true;
42 
43  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<std::vector<std::string> &>(_)))
44  .WillRepeatedly(Return(AwsError::AWS_ERR_OK));
45  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<double &>(_)))
46  .WillRepeatedly(Return(AwsError::AWS_ERR_OK));
47  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<std::string &>(_)))
48  .WillRepeatedly(Return(AwsError::AWS_ERR_OK));
49  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<Aws::String &>(_)))
50  .WillRepeatedly(DoAll(SetArgReferee<1>(expected_str), Return(AwsError::AWS_ERR_OK)));
51  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<int &>(_)))
52  .WillRepeatedly(DoAll(SetArgReferee<1>(kExpectedInt), Return(AwsError::AWS_ERR_OK)));
53  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<bool &>(_)))
54  .WillRepeatedly(DoAll(SetArgReferee<1>(kExpectedBool), Return(AwsError::AWS_ERR_OK)));
55 
56  ClientConfiguration config = test_subject_->GetClientConfiguration();
57 
58  EXPECT_EQ(expected_str, config.region);
59  EXPECT_EQ(kExpectedInt, config.maxConnections);
60  EXPECT_EQ(kExpectedBool, config.useDualStack);
61 }
62 
63 TEST_F(ClientConfigurationProviderFixture, TestAllReaderErrorsIgnored)
64 {
65  ClientConfiguration default_config;
66  const char* unexpected_str = (default_config.region + Aws::String("YjJiOWZmZDQ3Yjg1MTU0MmE3MjFmOTk2")).c_str();
67  const int unkExpectedInt = default_config.maxConnections + 45231;
68  const bool unkExpectedBool = !default_config.useDualStack;
69 
70  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<Aws::String &>(_)))
71  .WillRepeatedly(DoAll(SetArgReferee<1>(unexpected_str), Return(AwsError::AWS_ERR_FAILURE)));
72  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<int &>(_)))
73  .WillRepeatedly(DoAll(SetArgReferee<1>(unkExpectedInt), Return(AwsError::AWS_ERR_NOT_FOUND)));
74  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<bool &>(_)))
75  .WillRepeatedly(DoAll(SetArgReferee<1>(unkExpectedBool), Return(AwsError::AWS_ERR_EMPTY)));
76 
77  ClientConfiguration config = test_subject_->GetClientConfiguration();
78 
79  EXPECT_EQ(unexpected_str, config.region);
80  EXPECT_NE(unkExpectedInt, config.maxConnections);
81  EXPECT_EQ(unkExpectedBool, config.useDualStack);
82  EXPECT_EQ(default_config.maxConnections, config.maxConnections);
83  EXPECT_NE(default_config.useDualStack, config.useDualStack);
84 }
85 
86 TEST_F(ClientConfigurationProviderFixture, TestRosVersionOverride) {
87  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<Aws::String &>(_)))
88  .WillRepeatedly(Return(AwsError::AWS_ERR_NOT_FOUND));
89  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<int &>(_)))
90  .WillRepeatedly(Return(AwsError::AWS_ERR_NOT_FOUND));
91  EXPECT_CALL(*param_reader_, ReadParam(_, Matcher<bool &>(_)))
92  .WillRepeatedly(Return(AwsError::AWS_ERR_NOT_FOUND));
93 
94  ClientConfiguration config1 = test_subject_->GetClientConfiguration();
95  ClientConfiguration config2 = test_subject_->GetClientConfiguration("another_version");
96  EXPECT_NE(config1, config2);
97  config1.userAgent = config2.userAgent;
98  EXPECT_EQ(config1, config2);
99 }
100 
101 using client_conf_mutator = std::function<void(ClientConfiguration &)>;
103  public ::testing::TestWithParam<client_conf_mutator> { };
104 
105 TEST_P(ClientConfigurationOperatorsFixture, TestClientConfigurationEqNeqOperators)
106 {
107  ClientConfiguration config1, config2;
108 
109  EXPECT_EQ(config1, config2);
110 
111  GetParam()(config1);
112  EXPECT_NE(config1, config2);
113 }
114 
116 {
117  [](ClientConfiguration & config)->void { config.region = "OTg5ZWRiMWVhYjEyZDRkMWFhOTRlZGU0"; },
118  [](ClientConfiguration & config)->void { config.userAgent = "YmVkYjJjYTA0NTg0ZGJjZDdjOWY2OWYz"; },
119  [](ClientConfiguration & config)->void { config.endpointOverride = "MzllMmUxZWUzMmE3OWQ1MzZhZGQ0ZWM2"; },
120  [](ClientConfiguration & config)->void { config.proxyHost = "NzgzNzY5NDM5NTNjYmEzNGU0YmY3YjQ4"; },
121  [](ClientConfiguration & config)->void { config.proxyUserName = "NmU2MWE2NjhlMGEwYTc1NjU1ZDU0OGQw"; },
122  [](ClientConfiguration & config)->void { config.proxyPassword = "ZThkYmM1NmQwMWU1MTU1MDQ4YTA5NDFk"; },
123  [](ClientConfiguration & config)->void { config.caPath = "ZWM4Mzk1MTFiM2MyOTE2NzA0MThjMTYw"; },
124  [](ClientConfiguration & config)->void { config.caFile = "YzU5OGQzNmYzNWIzMjIzNDFlZDM3NGNh"; },
125  [](ClientConfiguration & config)->void { config.requestTimeoutMs = config.requestTimeoutMs + 12; },
126  [](ClientConfiguration & config)->void { config.connectTimeoutMs = config.connectTimeoutMs - 42; },
127  [](ClientConfiguration & config)->void { config.maxConnections = config.maxConnections + 1981; },
128  [](ClientConfiguration & config)->void { config.proxyPort = config.proxyPort + 2; },
129  [](ClientConfiguration & config)->void { config.useDualStack = ! config.useDualStack; },
130  [](ClientConfiguration & config)->void { config.enableClockSkewAdjustment = ! config.enableClockSkewAdjustment; },
131  [](ClientConfiguration & config)->void { config.followRedirects = !config.followRedirects; },
132  [](ClientConfiguration & config)->void { config.verifySSL = !config.verifySSL; }
133 };
135  TestClientConfigurationOperators,
137  ::testing::ValuesIn(g_client_conf_mutators)
138 );
139 
140 int main(int argc, char ** argv)
141 {
142  testing::InitGoogleTest(&argc, argv);
143  return RUN_ALL_TESTS();
144 }
std::function< void(ClientConfiguration &)> client_conf_mutator
TEST_P(ClientConfigurationOperatorsFixture, TestClientConfigurationEqNeqOperators)
int main(int argc, char **argv)
AwsError
Defines error return codes for functions This enum defines standard error codes that will be returned...
Definition: aws_error.h:29
TEST_F(ClientConfigurationProviderFixture, TestReaderRespected)
INSTANTIATE_TEST_CASE_P(TestClientConfigurationOperators, ClientConfigurationOperatorsFixture,::testing::ValuesIn(g_client_conf_mutators))
client_conf_mutator g_client_conf_mutators[]


aws_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:11:38