syncthingtray/testhelper/syncthingtestinstance.h
Martchus 037c5a309b Fail tests early when Syncthing exists unexpectedly or cannot be started at all
Before tests ran until a timeout was reached and failed not with a clear
error message stating the root cause. This is now the case and can be
tested by setting `SYNCTHING_PATH` to e.g. false/true or a non-existing
binary.

This may help with the test issue mentioned in
https://github.com/Martchus/syncthingtray/issues/144 although I could
never reproduce the concrete error message myself.
2022-10-29 21:22:21 +02:00

80 lines
1.9 KiB
C++

#ifndef SYNCTHINGTESTHELPER_SYNCTHINGTESTINSTANCE_H
#define SYNCTHINGTESTHELPER_SYNCTHINGTESTINSTANCE_H
#include "./global.h"
#include "./helper.h"
#include <syncthingconnector/syncthingprocess.h>
#include <QCoreApplication>
#include <QProcess>
using namespace std;
namespace CppUtilities {
/*!
* \brief The SyncthingTestInstance class provides running a test instance of Syncthing.
*
* The class is meant to be subclassed by tests requiring a running Syncthing instance.
*/
class SYNCTHINGTESTHELPER_EXPORT SyncthingTestInstance {
public:
SyncthingTestInstance();
const QString &apiKey() const;
const QString &syncthingPort() const;
QCoreApplication &application();
Data::SyncthingProcess &syncthingProcess();
public:
void start();
void stop();
bool isInterleavedOutputEnabled() const;
void setInterleavedOutputEnabled(bool interleavedOutputEnabled);
void setInterleavedOutputEnabledFromEnv();
private:
void handleError(QProcess::ProcessError error);
void handleFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
QString m_apiKey;
QString m_syncthingPort;
QCoreApplication m_app;
Data::SyncthingProcess m_syncthingProcess;
bool m_interleavedOutput;
bool m_processSupposedToRun;
};
inline const QString &SyncthingTestInstance::apiKey() const
{
return m_apiKey;
}
inline const QString &SyncthingTestInstance::syncthingPort() const
{
return m_syncthingPort;
}
inline QCoreApplication &SyncthingTestInstance::application()
{
return m_app;
}
inline Data::SyncthingProcess &SyncthingTestInstance::syncthingProcess()
{
return m_syncthingProcess;
}
/*!
* \brief Whether Syncthing's output should be forwarded to see what Syncthing and the test is doing at the same time.
*/
inline bool SyncthingTestInstance::isInterleavedOutputEnabled() const
{
return m_interleavedOutput;
}
} // namespace CppUtilities
#endif // SYNCTHINGTESTHELPER_SYNCTHINGTESTINSTANCE_H