mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 10:55:46 -05:00
[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.
This commit is contained in:
parent
846d6abaa8
commit
44ec8a7c0b
1 changed files with 17 additions and 11 deletions
|
@ -10,6 +10,7 @@
|
|||
#include "Paste.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "DllMacro.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QFile>
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue