Skip to content

Commit

Permalink
[tests] Check throwing when opening a SSH session.
Browse files Browse the repository at this point in the history
  • Loading branch information
luis4a0 committed Nov 10, 2023
1 parent ef5f739 commit 2a140bd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_daemon_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,43 @@ TEST_F(TestDaemonStart, successfulStartOkStatus)
EXPECT_TRUE(status.ok());
}

TEST_F(TestDaemonStart, messageOnSSHError)
{
REPLACE(ssh_new, []() { return nullptr; }); // This makes creating the SSH session throw.

std::vector<mp::NetworkInterface> unconfigured{{"eth7", "", true}};

auto mock_factory = use_a_mock_vm_factory();
const auto [temp_dir, filename] = plant_instance_json(fake_json_contents(mac_addr, unconfigured));

auto instance_ptr = std::make_unique<NiceMock<mpt::MockVirtualMachine>>(mock_instance_name);
EXPECT_CALL(*mock_factory, create_virtual_machine(_, _)).WillOnce([&instance_ptr](const auto&, auto&) {
return std::move(instance_ptr);
});

EXPECT_CALL(*instance_ptr, wait_until_ssh_up).WillRepeatedly(Return());
EXPECT_CALL(*instance_ptr, current_state()).WillRepeatedly(Return(mp::VirtualMachine::State::off));
EXPECT_CALL(*instance_ptr, start()).Times(1);
EXPECT_CALL(*instance_ptr, add_network_interface(_, _)).Times(1);

config_builder.data_directory = temp_dir->path();
config_builder.vault = std::make_unique<NiceMock<mpt::MockVMImageVault>>();

mp::Daemon daemon{config_builder.build()};

mp::StartRequest request;
request.mutable_instance_names()->add_instance_name(mock_instance_name);

StrictMock<mpt::MockServerReaderWriter<mp::StartReply, mp::StartRequest>> server;

EXPECT_CALL(server, Write(Property(&mp::StartReply::log_line, HasSubstr("Cannot create a SSH shell")), _)).Times(1);

auto status = call_daemon_slot(daemon, &mp::Daemon::start, request, std::move(server));

EXPECT_THAT(status.error_message(), StrEq(""));
EXPECT_TRUE(status.ok());
}

struct WithSSH : public TestDaemonStart, WithParamInterface<int>
{
};
Expand Down

0 comments on commit 2a140bd

Please sign in to comment.