Skip to content

Commit

Permalink
Merge #2226
Browse files Browse the repository at this point in the history
2226: Parse memory, disk parameters in the client. r=ricab a=luis4a0

Fixes #2224.

Co-authored-by: Luis Peñaranda <luis.penaranda@canonical.com>
  • Loading branch information
bors[bot] and luis4a0 authored Sep 16, 2021
2 parents fb522fc + f59d5bf commit 8cf75b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/cli/cmd/launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <multipass/exceptions/cmd_exceptions.h>
#include <multipass/exceptions/snap_environment_exception.h>
#include <multipass/format.h>
#include <multipass/memory_size.h>
#include <multipass/settings.h>
#include <multipass/snap_utils.h>
#include <multipass/utils.h>
Expand Down Expand Up @@ -277,12 +278,20 @@ mp::ParseCode cmd::Launch::parse_args(mp::ArgParser* parser)

if (parser->isSet(memOption))
{
request.set_mem_size(parser->value(memOption).toStdString());
auto arg_mem_size = parser->value(memOption).toStdString();

mp::MemorySize{arg_mem_size}; // throw if bad

request.set_mem_size(arg_mem_size);
}

if (parser->isSet(diskOption))
{
request.set_disk_space(parser->value(diskOption).toStdString());
auto arg_disk_size = parser->value(diskOption).toStdString();

mp::MemorySize{arg_disk_size}; // throw if bad

request.set_disk_space(arg_disk_size);
}

if (parser->isSet(cloudInitOption))
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,28 @@ TEST_F(Client, launch_cmd_good_arguments)
EXPECT_THAT(send_command({"launch", "foo"}), Eq(mp::ReturnCode::Ok));
}

TEST_F(Client, launch_cmd_wrong_mem_arguments)
{
EXPECT_CALL(mock_daemon, launch(_, _, _)).Times(0);
MP_EXPECT_THROW_THAT(send_command({"launch", "-m", "wrong"}), std::runtime_error,
mpt::match_what(HasSubstr("wrong is not a valid memory size")));
MP_EXPECT_THROW_THAT(send_command({"launch", "--mem", "1.23f"}), std::runtime_error,
mpt::match_what(HasSubstr("1.23f is not a valid memory size")));
MP_EXPECT_THROW_THAT(send_command({"launch", "-mem", "2048M"}), std::runtime_error,
mpt::match_what(HasSubstr("em is not a valid memory size"))); // note single dash
}

TEST_F(Client, launch_cmd_wrong_disk_arguments)
{
EXPECT_CALL(mock_daemon, launch(_, _, _)).Times(0);
MP_EXPECT_THROW_THAT(send_command({"launch", "-d", "wrong"}), std::runtime_error,
mpt::match_what(HasSubstr("wrong is not a valid memory size")));
MP_EXPECT_THROW_THAT(send_command({"launch", "--disk", "4.56f"}), std::runtime_error,
mpt::match_what(HasSubstr("4.56f is not a valid memory size")));
MP_EXPECT_THROW_THAT(send_command({"launch", "-disk", "8192M"}), std::runtime_error,
mpt::match_what(HasSubstr("isk is not a valid memory size"))); // note single dash
}

TEST_F(Client, launch_cmd_help_ok)
{
EXPECT_THAT(send_command({"launch", "-h"}), Eq(mp::ReturnCode::Ok));
Expand Down

0 comments on commit 8cf75b0

Please sign in to comment.