From b1a5044bbfa7265c8d123ae3ac9a172e853c5008 Mon Sep 17 00:00:00 2001 From: Fyodor Muratov Date: Wed, 2 Aug 2017 22:40:31 +0300 Subject: [PATCH] Small refactoring: Fix gtest equals usages Fix broken include paths --- test/module/iroha-cli/CMakeLists.txt | 7 +++- .../iroha-cli/bootstrap_network_test.cpp | 38 +++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/test/module/iroha-cli/CMakeLists.txt b/test/module/iroha-cli/CMakeLists.txt index 31ce5c2e0e..00ed09453f 100644 --- a/test/module/iroha-cli/CMakeLists.txt +++ b/test/module/iroha-cli/CMakeLists.txt @@ -4,6 +4,9 @@ target_link_libraries(bootstrap_network_test crypto ametsuchi ) +target_include_directories(bootstrap_network_test PUBLIC + ${PROJECT_SOURCE_DIR}/iroha-cli + ) addtest(client_test client_test.cpp) target_link_libraries(client_test @@ -11,4 +14,6 @@ target_link_libraries(client_test processors server_runner ) -target_include_directories(client_test PUBLIC ${PROJECT_SOURCE_DIR}/iroha-cli) +target_include_directories(client_test PUBLIC + ${PROJECT_SOURCE_DIR}/iroha-cli + ) diff --git a/test/module/iroha-cli/bootstrap_network_test.cpp b/test/module/iroha-cli/bootstrap_network_test.cpp index ab7df1aac2..af0bc1ee81 100644 --- a/test/module/iroha-cli/bootstrap_network_test.cpp +++ b/test/module/iroha-cli/bootstrap_network_test.cpp @@ -15,13 +15,13 @@ * limitations under the License. */ -#include "../../../iroha-cli/bootstrap_network.hpp" +#include #include +#include "bootstrap_network.hpp" #include -#include #include #include -#include "../../../iroha-cli/genesis_block_client.hpp" +#include "genesis_block_client.hpp" #include "ametsuchi/block_serializer.hpp" #include "common/types.hpp" #include "crypto/crypto.hpp" @@ -112,32 +112,33 @@ TEST_F(iroha_cli_test, NormalWhenParseTrustedPeers) { MockGenesisBlockClient client_mock; iroha_cli::BootstrapNetwork bootstrap(client_mock); auto peers = bootstrap.parse_trusted_peers(test_path); - ASSERT_EQ(peers.size(), 4); - ASSERT_STREQ(peers[0].address.c_str(), "192.168.0.3"); - ASSERT_STREQ(peers[1].address.c_str(), "192.168.0.4"); - ASSERT_STREQ(peers[2].address.c_str(), "192.168.0.5"); - ASSERT_STREQ(peers[3].address.c_str(), "192.168.0.6"); - ASSERT_TRUE(remove(test_path) == 0); + ASSERT_EQ(4, peers.size()); + ASSERT_STREQ("192.168.0.3", peers[0].address.c_str()); + ASSERT_STREQ("192.168.0.4", peers[1].address.c_str()); + ASSERT_STREQ("192.168.0.5", peers[2].address.c_str()); + ASSERT_STREQ("192.168.0.6", peers[3].address.c_str()); + ASSERT_EQ(0, remove(test_path)); } TEST_F(iroha_cli_test, WrongIPNameWhenParseTrustedPeers) { auto test_path = "/tmp/_bootstrap_test_target.conf"; std::ofstream ofs(test_path); ofs << R"({"peers":[{"pubkey":")" + rnd_hex_pk() + - R"(", "Ip":"192.168.0.5"}]})"; - ofs.close(); + R"(", "Ip":"192.168.0.5"}]})"; MockGenesisBlockClient client_mock; iroha_cli::BootstrapNetwork bootstrap(client_mock); - ASSERT_ANY_THROW({ bootstrap.parse_trusted_peers(test_path); }); - ASSERT_TRUE(remove(test_path) == 0); + ASSERT_ANY_THROW({ // todo fix + bootstrap.parse_trusted_peers(test_path); + }); + ASSERT_EQ(0, remove(test_path)); } TEST_F(iroha_cli_test, InvalidIPValueWhenParseTrustedPeers) { auto test_path = "/tmp/_bootstrap_test_target.conf"; std::ofstream ofs(test_path); ofs << R"({"peers":[{"pubkey":")" + rnd_hex_pk() + - R"(", "ip":"192.256.0.5"}]})"; + R"(", "ip":"192.256.0.5"}]})"; ofs.close(); MockGenesisBlockClient client_mock; @@ -190,7 +191,7 @@ TEST_F(iroha_cli_test, NormalWhenParseGenesisBlock) { MockGenesisBlockClient client_mock; iroha_cli::BootstrapNetwork bootstrap(client_mock); auto genesis = bootstrap.parse_genesis_block(test_path); - ASSERT_TRUE(remove(test_path) == 0); + ASSERT_EQ(0, remove(test_path)); } TEST_F(iroha_cli_test, MergeAddTrustedPeersWhenCreatingGenesisBlock) { @@ -216,9 +217,6 @@ TEST_F(iroha_cli_test, MergeAddTrustedPeersWhenCreatingGenesisBlock) { TEST_F(iroha_cli_test, NormalWhenRunNetwork) { MockGenesisBlockClient client_mock; iroha::protocol::ApplyGenesisBlockResponse response; - // EXPECT_CALL(set_channel, set_channel("192.168.0.3", "192.168.0.4")) - // EXPECT_CALL(send_genesis_block, send_genesis_block(block, response)) - // .WillRepeatedly(Return(grpc::Status::OK)); iroha_cli::BootstrapNetwork bootstrap(client_mock); @@ -230,5 +228,7 @@ TEST_F(iroha_cli_test, NormalWhenRunNetwork) { peers[1].address = "192.168.0.4"; peers[1].pubkey = iroha::create_keypair(iroha::create_seed()).pubkey; - ASSERT_NO_THROW({ bootstrap.run_network(peers, block); }); + ASSERT_NO_THROW({ + bootstrap.run_network(peers, block); + }); }