Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/client/cli/cmd/launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,14 @@ mp::ReturnCodeVariant cmd::Launch::request_launch(const ArgParser* parser)
}
else if (error == LaunchError::INVALID_HOSTNAME)
{
error_details =
fmt::format("Invalid instance name supplied: {}", request.instance_name());
error_details = fmt::format(
"Invalid instance name supplied: {}\n"
"Instance names must be valid, non-qualified host names: they may contain "
"only alphanumeric characters and hyphens, must start with a letter, and "
"must end with a letter or number. See "
"https://canonical.com/multipass/docs/stable/reference/"
"instance-name-format/",
request.instance_name());
}
else if (error == LaunchError::INVALID_NETWORK)
{
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_cli_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,28 @@ TEST_F(Client, launchCmdWithUnavailableZoneFails)
EXPECT_THAT(send_command({"launch", "--zone", "zone1"}), Eq(mp::ReturnCode::CommandFail));
}

TEST_F(Client, launchCmdWithInvalidNameExplainsRules)
{
const auto request_matcher = Property(&mp::LaunchRequest::instance_name, StrEq("1nvalid-name"));
mp::LaunchError launch_error;
launch_error.add_error_codes(mp::LaunchError::INVALID_HOSTNAME);
const auto failure = grpc::Status{grpc::StatusCode::INVALID_ARGUMENT,
"msg",
launch_error.SerializeAsString()};
EXPECT_CALL(mock_daemon, launch)
.WillOnce(
WithArg<1>(check_request_and_return<mp::LaunchReply, mp::LaunchRequest>(request_matcher,
failure)));

std::ostringstream cerr_stream;
EXPECT_THAT(send_command({"launch", "--name", "1nvalid-name"}, trash_stream, cerr_stream),
Eq(mp::ReturnCode::CommandFail));
EXPECT_THAT(cerr_stream.str(),
AllOf(HasSubstr("Invalid instance name supplied: 1nvalid-name"),
HasSubstr("only alphanumeric characters and hyphens"),
HasSubstr("instance-name-format")));
}

TEST_F(Client, launchCmdWithTimer)
{
EXPECT_CALL(mock_daemon, launch(_, _));
Expand Down
Loading