diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 10:34:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 16:26:38 +0100 |
commit | 3ac6cf5ffae2247719730f328d1363c498e4ee83 (patch) | |
tree | dbef67a345ec412c58eff6275111df29de7fa742 /tests/teststore.cpp | |
parent | e6f83f7b5af1ed3467d12f551fb7401238b7855e (diff) | |
download | kube-3ac6cf5ffae2247719730f328d1363c498e4ee83.tar.gz kube-3ac6cf5ffae2247719730f328d1363c498e4ee83.zip |
Dynamically setup initial test state
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r-- | tests/teststore.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp new file mode 100644 index 00000000..a8cd0b2d --- /dev/null +++ b/tests/teststore.cpp | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "teststore.h" | ||
20 | |||
21 | #include <sink/store.h> | ||
22 | |||
23 | #include <QDebug> | ||
24 | #include <QVariant> | ||
25 | |||
26 | using namespace Kube; | ||
27 | |||
28 | static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) | ||
29 | { | ||
30 | for (const auto &entry : list) { | ||
31 | auto object = entry.toMap(); | ||
32 | callback(object); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | void TestStore::setup(const QVariantMap &map) | ||
37 | { | ||
38 | iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) { | ||
39 | auto resource = [&] { | ||
40 | if (object["type"] == "dummy") { | ||
41 | return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray()); | ||
42 | } | ||
43 | if (object["type"] == "mailtransport") { | ||
44 | return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray()); | ||
45 | } | ||
46 | Q_ASSERT(false); | ||
47 | return Sink::ApplicationDomain::SinkResource{}; | ||
48 | }(); | ||
49 | Sink::Store::create(resource).exec().waitForFinished(); | ||
50 | }); | ||
51 | |||
52 | iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { | ||
53 | auto identity = Sink::ApplicationDomain::Identity{}; | ||
54 | identity.setAccount(object["account"].toByteArray()); | ||
55 | identity.setAddress(object["address"].toString()); | ||
56 | identity.setName(object["name"].toString()); | ||
57 | Sink::Store::create(identity).exec().waitForFinished(); | ||
58 | }); | ||
59 | } | ||