From 44ec8a7c0b75f56c89accd1391c8e748f23efb34 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Mar 2021 17:22:48 +0100 Subject: [PATCH] [libcalamaresui] Improve testability - mark functions with STATICTEST so they can be compiled into a test - move logfile-reading so we can call the pastebin-upload functions with an arbitrary payload. --- src/libcalamaresui/utils/Paste.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index d723e182c..ee54d265a 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -10,6 +10,7 @@ #include "Paste.h" #include "Branding.h" +#include "DllMacro.h" #include "utils/Logger.h" #include @@ -20,7 +21,7 @@ * * Returns an empty QByteArray() on any kind of error. */ -static QByteArray +STATICTEST QByteArray logFileContents() { QFile pasteSourceFile( Logger::logFile() ); @@ -34,16 +35,9 @@ logFileContents() } -static QString -ficheLogUpload( const QUrl& serverUrl, QObject* parent ) +STATICTEST QString +ficheLogUpload( const QByteArray& pasteData, QUrl& serverUrl, QObject* parent ) { - QByteArray pasteData = logFileContents(); - if ( pasteData.isEmpty() ) - { - // An error has already been logged - return QString(); - } - QTcpSocket* socket = new QTcpSocket( parent ); socket->connectToHost( serverUrl.host(), serverUrl.port() ); @@ -100,6 +94,18 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent ) cWarning() << "Upload configure with invalid URL"; return QString(); } + if ( type == Calamares::Branding::UploadServerType::None ) + { + // Early return to avoid reading the log file + return QString(); + } + + QByteArray pasteData = logFileContents(); + if ( pasteData.isEmpty() ) + { + // An error has already been logged + return QString(); + } switch ( type ) { @@ -107,7 +113,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent ) cWarning() << "No upload configured."; return QString(); case Calamares::Branding::UploadServerType::Fiche: - return ficheLogUpload( serverUrl, parent ); + return ficheLogUpload( pasteData, serverUrl, parent ); } return QString(); }