[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.
main
Adriaan de Groot 4 years ago
parent 846d6abaa8
commit 44ec8a7c0b

@ -10,6 +10,7 @@
#include "Paste.h" #include "Paste.h"
#include "Branding.h" #include "Branding.h"
#include "DllMacro.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QFile> #include <QFile>
@ -20,7 +21,7 @@
* *
* Returns an empty QByteArray() on any kind of error. * Returns an empty QByteArray() on any kind of error.
*/ */
static QByteArray STATICTEST QByteArray
logFileContents() logFileContents()
{ {
QFile pasteSourceFile( Logger::logFile() ); QFile pasteSourceFile( Logger::logFile() );
@ -34,16 +35,9 @@ logFileContents()
} }
static QString STATICTEST QString
ficheLogUpload( const QUrl& serverUrl, QObject* parent ) 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 ); QTcpSocket* socket = new QTcpSocket( parent );
socket->connectToHost( serverUrl.host(), serverUrl.port() ); socket->connectToHost( serverUrl.host(), serverUrl.port() );
@ -100,6 +94,18 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent )
cWarning() << "Upload configure with invalid URL"; cWarning() << "Upload configure with invalid URL";
return QString(); 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 ) switch ( type )
{ {
@ -107,7 +113,7 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent )
cWarning() << "No upload configured."; cWarning() << "No upload configured.";
return QString(); return QString();
case Calamares::Branding::UploadServerType::Fiche: case Calamares::Branding::UploadServerType::Fiche:
return ficheLogUpload( serverUrl, parent ); return ficheLogUpload( pasteData, serverUrl, parent );
} }
return QString(); return QString();
} }

Loading…
Cancel
Save