mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-19 00:15:21 +01:00
Add integration tests
Tests if repository json files conform to the json schema. If all resources (images/icons/website URLs) they mention actually exists. And can also test writing images and the FAT modification code.
This commit is contained in:
parent
fce80b2a67
commit
05f1c4dbb5
11 changed files with 319 additions and 8 deletions
85
src/cli.cpp
85
src/cli.cpp
|
@ -57,6 +57,15 @@ int Cli::main()
|
|||
parser.addOption(writeSystemDrive);
|
||||
QCommandLineOption sha256Option("sha256", "Expected hash", "sha256", "");
|
||||
parser.addOption(sha256Option);
|
||||
QCommandLineOption cacheFileOption("cache-file", "Custom cache file (requires setting sha256 as well)", "cache-file", "");
|
||||
parser.addOption(cacheFileOption);
|
||||
QCommandLineOption firstRunScriptOption("first-run-script", "Add firstrun.sh to image", "first-run-script", "");
|
||||
parser.addOption(firstRunScriptOption);
|
||||
QCommandLineOption userdataOption("cloudinit-userdata", "Add cloud-init user-data file to image", "cloudinit-userdata", "");
|
||||
parser.addOption(userdataOption);
|
||||
QCommandLineOption networkconfigOption("cloudinit-networkconfig", "Add cloud-init network-config file to image", "cloudinit-networkconfig", "");
|
||||
parser.addOption(networkconfigOption);
|
||||
|
||||
QCommandLineOption debugOption("debug", "Output debug messages to console");
|
||||
parser.addOption(debugOption);
|
||||
QCommandLineOption quietOption("quiet", "Only write to console on error");
|
||||
|
@ -69,7 +78,7 @@ int Cli::main()
|
|||
const QStringList args = parser.positionalArguments();
|
||||
if (args.count() != 2)
|
||||
{
|
||||
std::cerr << "Usage: --cli [--disable-verify] [--sha256 <expected hash>] [--debug] [--quiet] <image file to write> <destination drive device>" << std::endl;
|
||||
std::cerr << "Usage: --cli [--disable-verify] [--sha256 <expected hash> [--cache-file <cache file>]] [--first-run-script <script>] [--debug] [--quiet] <image file to write> <destination drive device>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -78,10 +87,17 @@ int Cli::main()
|
|||
qInstallMessageHandler(devnullMsgHandler);
|
||||
}
|
||||
_quiet = parser.isSet(quietOption);
|
||||
QByteArray initFormat = (parser.value(userdataOption).isEmpty()
|
||||
&& parser.value(networkconfigOption).isEmpty() ) ? "systemd" : "cloudinit";
|
||||
|
||||
if (args[0].startsWith("http:", Qt::CaseInsensitive) || args[0].startsWith("https:", Qt::CaseInsensitive))
|
||||
{
|
||||
_imageWriter->setSrc(args[0], 0, 0, parser.value(sha256Option).toLatin1() );
|
||||
_imageWriter->setSrc(args[0], 0, 0, parser.value(sha256Option).toLatin1(), false, "", "", initFormat);
|
||||
|
||||
if (!parser.value(cacheFileOption).isEmpty())
|
||||
{
|
||||
_imageWriter->setCustomCacheFile(parser.value(cacheFileOption), parser.value(sha256Option).toLatin1() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -89,7 +105,7 @@ int Cli::main()
|
|||
|
||||
if (fi.isFile())
|
||||
{
|
||||
_imageWriter->setSrc(QUrl::fromLocalFile(args[0]), fi.size(), 0, parser.value(sha256Option).toLatin1() );
|
||||
_imageWriter->setSrc(QUrl::fromLocalFile(args[0]), fi.size(), 0, parser.value(sha256Option).toLatin1(), false, "", "", initFormat);
|
||||
}
|
||||
else if (!fi.exists())
|
||||
{
|
||||
|
@ -140,6 +156,69 @@ int Cli::main()
|
|||
}
|
||||
}
|
||||
|
||||
if (!parser.value(userdataOption).isEmpty())
|
||||
{
|
||||
QByteArray userData, networkConfig;
|
||||
QFile f(parser.value(userdataOption));
|
||||
|
||||
if (!f.exists())
|
||||
{
|
||||
std::cerr << "Error: user-data file does not exists" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (f.open(f.ReadOnly))
|
||||
{
|
||||
userData = f.readAll();
|
||||
f.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: opening user-data file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
f.setFileName(parser.value(networkconfigOption));
|
||||
if (!f.exists())
|
||||
{
|
||||
std::cerr << "Error: network-config file does not exists" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (f.open(f.ReadOnly))
|
||||
{
|
||||
networkConfig = f.readAll();
|
||||
f.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: opening network-config file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
_imageWriter->setImageCustomization("", "", "", userData, networkConfig);
|
||||
}
|
||||
else if (!parser.value(firstRunScriptOption).isEmpty())
|
||||
{
|
||||
QByteArray firstRunScript;
|
||||
QFile f(parser.value(firstRunScriptOption));
|
||||
if (!f.exists())
|
||||
{
|
||||
std::cerr << "Error: firstrun script does not exists" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (f.open(f.ReadOnly))
|
||||
{
|
||||
firstRunScript = f.readAll();
|
||||
f.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: opening firstrun script" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
_imageWriter->setImageCustomization("", "", firstRunScript, "", "");
|
||||
}
|
||||
|
||||
_imageWriter->setDst(args[1]);
|
||||
_imageWriter->setVerifyEnabled(!parser.isSet(disableVerify));
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
ImageWriter::ImageWriter(QObject *parent)
|
||||
: QObject(parent), _repo(QUrl(QString(OSLIST_URL))), _dlnow(0), _verifynow(0),
|
||||
_engine(nullptr), _thread(nullptr), _verifyEnabled(false), _cachingEnabled(false),
|
||||
_embeddedMode(false), _online(false), _trans(nullptr)
|
||||
_embeddedMode(false), _online(false), _customCacheFile(false), _trans(nullptr)
|
||||
{
|
||||
connect(&_polltimer, SIGNAL(timeout()), SLOT(pollProgress()));
|
||||
|
||||
|
@ -349,8 +349,11 @@ void ImageWriter::startWrite()
|
|||
|
||||
void ImageWriter::onCacheFileUpdated(QByteArray sha256)
|
||||
{
|
||||
_settings.setValue("caching/lastDownloadSHA256", sha256);
|
||||
_settings.sync();
|
||||
if (!_customCacheFile)
|
||||
{
|
||||
_settings.setValue("caching/lastDownloadSHA256", sha256);
|
||||
_settings.sync();
|
||||
}
|
||||
_cachedFileHash = sha256;
|
||||
qDebug() << "Done writing cache file";
|
||||
}
|
||||
|
@ -421,6 +424,14 @@ void ImageWriter::setCustomOsListUrl(const QUrl &url)
|
|||
_repo = url;
|
||||
}
|
||||
|
||||
void ImageWriter::setCustomCacheFile(const QString &cacheFile, const QByteArray &sha256)
|
||||
{
|
||||
_cacheFileName = cacheFile;
|
||||
_cachedFileHash = QFile::exists(cacheFile) ? sha256 : "";
|
||||
_customCacheFile = true;
|
||||
_cachingEnabled = true;
|
||||
}
|
||||
|
||||
/* Start polling the list of available drives */
|
||||
void ImageWriter::startDriveListPolling()
|
||||
{
|
||||
|
|
|
@ -74,6 +74,9 @@ public:
|
|||
/* Set custom repository */
|
||||
Q_INVOKABLE void setCustomOsListUrl(const QUrl &url);
|
||||
|
||||
/* Set custom cache file */
|
||||
void setCustomCacheFile(const QString &cacheFile, const QByteArray &sha256);
|
||||
|
||||
/* Utility function to open OS file dialog */
|
||||
Q_INVOKABLE void openFileDialog();
|
||||
|
||||
|
@ -168,6 +171,7 @@ protected:
|
|||
bool _verifyEnabled, _multipleFilesInZip, _cachingEnabled, _embeddedMode, _online;
|
||||
QSettings _settings;
|
||||
QMap<QString,QString> _translations;
|
||||
bool _customCacheFile;
|
||||
QTranslator *_trans;
|
||||
#ifdef Q_OS_WIN
|
||||
QWinTaskbarButton *_taskbarButton;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue