Extend the live-CLI integration test to assert that installing an app links its .desktop entry into ~/.local/share/applications, and that uninstalling cleans the link back up. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
#include "flatpak-manager.h"
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
// Real end-to-end exercise of the Flatpak provider against the live `flatpak`
|
|
// CLI: install a small app, verify it is listed and marked as installed in
|
|
// search, run update/refresh, then uninstall. It validates the exact commands
|
|
// the application runs (install fallbacks included) instead of only parsing.
|
|
//
|
|
// Skipped (with a message) when the flatpak binary is not available so the
|
|
// suite stays green on systems without it.
|
|
//
|
|
// The test is non-destructive for pre-existing installs: if the app is already
|
|
// present when the test starts it is left in place, only verified and updated.
|
|
|
|
namespace {
|
|
|
|
const std::string kApp = "org.gnome.Calculator";
|
|
|
|
bool isInstalled(FlatpakManager& fm) {
|
|
for (const auto& pkg : fm.listInstalled()) {
|
|
if (pkg.name == kApp) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
fs::path desktopLink() {
|
|
const char* home = std::getenv("HOME");
|
|
return fs::path(home ? home : "/tmp") / ".local/share/applications" / (kApp + ".desktop");
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
if (system("which flatpak > /dev/null 2>&1") != 0) {
|
|
std::cout << "flatpak not installed, skipping integration test" << std::endl;
|
|
return 0;
|
|
}
|
|
|
|
FlatpakManager fm;
|
|
const bool preinstalled = isInstalled(fm);
|
|
|
|
// 1. Install through the provider's own logic (remote-add + fallbacks).
|
|
if (!fm.install(kApp, nullptr)) {
|
|
std::cout << "FAIL install: " << fm.lastError() << std::endl;
|
|
return 1;
|
|
}
|
|
if (!isInstalled(fm)) {
|
|
std::cout << "FAIL install: app not listed as installed" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// 1b. The app must be linked into the user's standard applications dir so it
|
|
// appears in any desktop launcher (the pacman-like integration).
|
|
if (fs::is_symlink(desktopLink())) {
|
|
std::cout << "OK desktop integration present" << std::endl;
|
|
} else {
|
|
std::cout << "FAIL install: no .desktop link in ~/.local/share/applications" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// 2. Updating the single app and all apps must complete without error.
|
|
if (!fm.update(kApp, nullptr)) {
|
|
std::cout << "FAIL update(app): " << fm.lastError() << std::endl;
|
|
return 1;
|
|
}
|
|
if (!fm.update("", nullptr)) {
|
|
std::cout << "FAIL update(all): " << fm.lastError() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// 3. Refreshing the appstream metadata must complete without error.
|
|
if (!fm.refresh(nullptr)) {
|
|
std::cout << "FAIL refresh: " << fm.lastError() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// 4. Search must find the app and report it as installed (not "Disponible").
|
|
bool searchFound = false;
|
|
for (const auto& pkg : fm.search("calculator")) {
|
|
if (pkg.name == kApp) {
|
|
searchFound = true;
|
|
if (!pkg.installed) {
|
|
std::cout << "FAIL search: app not flagged as installed" << std::endl;
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
if (!searchFound) {
|
|
std::cout << "FAIL search: app not found in results" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// 5. Uninstall, unless the app was already there before the test started.
|
|
if (!preinstalled) {
|
|
if (!fm.remove(kApp, nullptr)) {
|
|
std::cout << "FAIL remove: " << fm.lastError() << std::endl;
|
|
return 1;
|
|
}
|
|
if (isInstalled(fm)) {
|
|
std::cout << "FAIL remove: app still listed as installed" << std::endl;
|
|
return 1;
|
|
}
|
|
if (fs::is_symlink(desktopLink())) {
|
|
std::cout << "FAIL remove: desktop link not removed" << std::endl;
|
|
return 1;
|
|
} else {
|
|
std::cout << "OK desktop integration removed" << std::endl;
|
|
}
|
|
} else {
|
|
// Pre-existing app: verify the launcher link exists (integration ran).
|
|
if (!fs::is_symlink(desktopLink())) {
|
|
std::cout << "OK desktop integration ensured for preinstalled app" << std::endl;
|
|
}
|
|
}
|
|
|
|
std::cout << "All flatpak integration tests passed." << std::endl;
|
|
return 0;
|
|
}
|