Skip to content

Commit 4b90041

Browse files
committed
[cli] fix no-os case in table formatter output for FindReply
1 parent 1233271 commit 4b90041

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/client/cli/formatter/table_formatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ std::string mp::TableFormatter::format(const FindReply& reply) const
156156
fmt::format_to(buf, "{:<24}{:<18}{:<17}{:<}\n",
157157
(alias->remote_name().empty() ? "" : alias->remote_name() + ":") + alias->alias(),
158158
fmt::format("{}", fmt::join(aliases.cbegin() + 1, aliases.cend(), ",")), image.version(),
159-
fmt::format("{} {}", image.os(), image.release()));
159+
fmt::format("{}{}", image.os().empty() ? "" : image.os() + " ", image.release()));
160160
}
161161

162162
return fmt::to_string(buf);

tests/test_output_formatter.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ auto construct_find_one_reply()
176176
return reply;
177177
}
178178

179+
auto construct_find_one_reply_no_os()
180+
{
181+
auto reply = mp::FindReply();
182+
183+
auto image_entry = reply.add_images_info();
184+
image_entry->set_release("Snapcraft builder for core16");
185+
image_entry->set_version("20190520");
186+
187+
auto alias_entry = image_entry->add_aliases_info();
188+
alias_entry->set_alias("core18");
189+
alias_entry->set_remote_name("snapcraft");
190+
191+
return reply;
192+
}
193+
179194
auto construct_find_multiple_replies()
180195
{
181196
auto reply = mp::FindReply();
@@ -400,6 +415,19 @@ TEST_F(TableFormatter, filtered_aliases_in_find_output)
400415
EXPECT_EQ(output, expected_output);
401416
}
402417

418+
TEST_F(TableFormatter, well_formatted_empty_os_find_output)
419+
{
420+
mp::TableFormatter formatter;
421+
const auto reply = construct_find_one_reply_no_os();
422+
423+
auto expected_output = "Image Aliases Version Description\n"
424+
"snapcraft:core18 eoan,devel 20190516 Snapcraft builder for core18\n";
425+
426+
auto output = formatter.format(reply);
427+
428+
EXPECT_EQ(output, expected_output);
429+
}
430+
403431
TEST_F(TableFormatter, no_images_find_output)
404432
{
405433
mp::FindReply find_reply;

0 commit comments

Comments
 (0)