Skip to content

Commit

Permalink
Small refactoring:
Browse files Browse the repository at this point in the history
Fix gtest equals usages
Fix broken include paths
  • Loading branch information
muratovv authored and lebdron committed Aug 2, 2017
1 parent bb6a23c commit b1a5044
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
7 changes: 6 additions & 1 deletion test/module/iroha-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ 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
client
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
)
38 changes: 19 additions & 19 deletions test/module/iroha-cli/bootstrap_network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* limitations under the License.
*/

#include "../../../iroha-cli/bootstrap_network.hpp"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "bootstrap_network.hpp"
#include <grpc++/grpc++.h>
#include <gtest/gtest.h>
#include <fstream>
#include <memory>
#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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand All @@ -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);
});
}

0 comments on commit b1a5044

Please sign in to comment.