// CLI Download Command tests // Catch2 tests for download command option parsing and daemon job controls. #include #include #include #include #include #include #include namespace yams::cli { std::unique_ptr createDownloadCommand(); } namespace { void parseDownloadCommandWithHelp(const std::vector& argv) { CLI::App app{"yams"}; auto downloadCmd = yams::cli::createDownloadCommand(); downloadCmd->registerCommand(app, /*cli*/ nullptr); bool gotHelp = false; bool gotParseError = false; std::string parseErrorMsg; try { app.parse(static_cast(argv.size()), const_cast(argv.data())); } catch (const CLI::CallForHelp&) { gotHelp = true; } catch (const CLI::ParseError& e) { gotParseError = true; parseErrorMsg = e.what(); } CHECK(gotHelp); if (gotParseError) { FAIL("Unexpected parse error: " << parseErrorMsg); } } } // namespace TEST_CASE("DownloadCommand - help shows daemon job options", "[cli][download][catch2]") { auto cli = std::make_unique(); const char* argv[] = {"yams", "download", "--help"}; REQUIRE_NOTHROW((void)cli->run(3, const_cast(argv))); } TEST_CASE("DownloadCommand - url download flags parse with help", "[cli][download][catch2]") { parseDownloadCommandWithHelp({"yams", "download", "https://example.com/file.txt", "--checksum", "sha256:deadbeef", "--tag", "archive", "--meta", "owner=opencode", "--json", "--help"}); } TEST_CASE("DownloadCommand - status action parses with help", "[cli][download][catch2]") { parseDownloadCommandWithHelp({"yams", "download", "--status", "job-123", "--json", "--help"}); } TEST_CASE("DownloadCommand - list jobs action parses with help", "[cli][download][catch2]") { parseDownloadCommandWithHelp({"yams", "download", "--list-jobs", "--json", "--help"}); } TEST_CASE("DownloadCommand - cancel action parses with help", "[cli][download][catch2]") { parseDownloadCommandWithHelp({"yams", "download", "--cancel", "job-456", "--help"}); }