Changeset View
Changeset View
Standalone View
Standalone View
plugins/docker/tests/test_docker.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * This file was partly taken from KDevelop's cvs plugin * | ||||
3 | * Copyright 2017 Aleix Pol Gonzalez <aleixpol@kde.org> * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or * | ||||
6 | * modify it under the terms of the GNU General Public License as * | ||||
7 | * published by the Free Software Foundation; either version 2 of * | ||||
8 | * the License or (at your option) version 3 or any later version * | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved * | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy * | ||||
11 | * defined in Section 14 of version 3 of the license. * | ||||
12 | * * | ||||
13 | * This program is distributed in the hope that it will be useful, * | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
16 | * GNU General Public License for more details. * | ||||
17 | * * | ||||
18 | * You should have received a copy of the GNU General Public License * | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||||
20 | ***************************************************************************/ | ||||
21 | | ||||
22 | #include <tests/autotestshell.h> | ||||
23 | #include <tests/testproject.h> | ||||
24 | #include <tests/testcore.h> | ||||
25 | #include <interfaces/iplugincontroller.h> | ||||
26 | #include <interfaces/iruntimecontroller.h> | ||||
27 | #include <interfaces/iruntime.h> | ||||
28 | | ||||
29 | #include <QJsonObject> | ||||
30 | #include <QLoggingCategory> | ||||
31 | #include <QProcess> | ||||
32 | #include <QtTest> | ||||
33 | | ||||
34 | using namespace KDevelop; | ||||
35 | | ||||
36 | static QString s_testedImage = QStringLiteral("ubuntu:17.04"); | ||||
37 | | ||||
38 | class DockerTest: public QObject | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | public: | ||||
42 | | ||||
43 | DockerTest() { | ||||
44 | QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.projectmanagers.cmake.debug=true\n")); | ||||
45 | | ||||
46 | auto ret = QProcess::execute("docker", {"pull", s_testedImage}); | ||||
47 | Q_ASSERT(ret == 0); | ||||
48 | | ||||
49 | AutoTestShell::init({QStringLiteral("kdevdocker")}); | ||||
50 | TestCore::initialize(); | ||||
51 | | ||||
52 | m_initialRuntime = ICore::self()->runtimeController()->currentRuntime(); | ||||
53 | | ||||
54 | auto plugin = ICore::self()->pluginController()->loadPlugin("kdevdocker"); | ||||
55 | Q_ASSERT(plugin); | ||||
56 | | ||||
57 | QSignalSpy spy(plugin, SIGNAL(imagesListed())); | ||||
58 | Q_ASSERT(spy.wait()); | ||||
59 | | ||||
60 | | ||||
61 | auto projectPath = QUrl::fromLocalFile(QFINDTESTDATA("testproject/test.kdev4")); | ||||
62 | qDebug() << "wuuu" << projectPath; | ||||
63 | TestCore::self()->projectController()->openProject(projectPath); | ||||
64 | QSignalSpy spy2(TestCore::self()->projectController(), &IProjectController::projectOpened); | ||||
65 | Q_ASSERT(spy2.wait()); | ||||
66 | | ||||
67 | } | ||||
68 | IRuntime* m_initialRuntime; | ||||
69 | | ||||
70 | private Q_SLOTS: | ||||
71 | void initTestCase() { | ||||
72 | QVERIFY(ICore::self()->runtimeController()->currentRuntime() == m_initialRuntime); | ||||
73 | for(IRuntime* runtime : ICore::self()->runtimeController()->availableRuntimes()) { | ||||
74 | if (s_testedImage == runtime->name()) { | ||||
75 | ICore::self()->runtimeController()->setCurrentRuntime(runtime); | ||||
76 | } | ||||
77 | } | ||||
78 | QVERIFY(ICore::self()->runtimeController()->currentRuntime() != m_initialRuntime); | ||||
79 | } | ||||
80 | | ||||
81 | void paths() { | ||||
82 | auto rt = ICore::self()->runtimeController()->currentRuntime(); | ||||
83 | QVERIFY(rt); | ||||
84 | | ||||
85 | const Path root("/"); | ||||
86 | const Path hostDir = rt->pathInHost(root); | ||||
87 | QCOMPARE(root, rt->pathInRuntime(hostDir)); | ||||
88 | } | ||||
89 | | ||||
90 | void projectPath() { | ||||
91 | auto rt = ICore::self()->runtimeController()->currentRuntime(); | ||||
92 | QVERIFY(rt); | ||||
93 | auto project = ICore::self()->projectController()->projects().first(); | ||||
94 | QVERIFY(project); | ||||
95 | | ||||
96 | const Path file = project->projectFile(); | ||||
97 | QCOMPARE(file, rt->pathInRuntime(rt->pathInHost(file))); | ||||
98 | QCOMPARE(project->path(), rt->pathInHost(rt->pathInRuntime(project->path()))); | ||||
99 | } | ||||
100 | | ||||
101 | void envs() { | ||||
102 | auto rt = ICore::self()->runtimeController()->currentRuntime(); | ||||
103 | QVERIFY(rt); | ||||
104 | | ||||
105 | QCOMPARE(rt->getenv("PATH"), QByteArray("/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")); | ||||
106 | } | ||||
107 | | ||||
108 | void cleanupTestCase() { | ||||
109 | ICore::self()->runtimeController()->setCurrentRuntime(m_initialRuntime); | ||||
110 | } | ||||
111 | | ||||
112 | }; | ||||
113 | | ||||
114 | QTEST_MAIN( DockerTest ) | ||||
115 | | ||||
116 | #include "test_docker.moc" |