File: test_docker.cpp

package info (click to toggle)
kdevelop 4%3A5.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 52,544 kB
  • sloc: cpp: 254,897; python: 3,380; sh: 1,271; ansic: 657; xml: 221; php: 95; makefile: 36; lisp: 13; sed: 12
file content (153 lines) | stat: -rw-r--r-- 6,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
 *   This file was partly taken from KDevelop's cvs plugin                 *
 *   Copyright 2017 Aleix Pol Gonzalez <aleixpol@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as        *
 *   published by the Free Software Foundation; either version 2 of        *
 *   the License or (at your option) version 3 or any later version        *
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 *   defined in Section 14 of version 3 of the license.                    *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#include <tests/autotestshell.h>
#include <tests/testproject.h>
#include <tests/testcore.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/iruntimecontroller.h>
#include <interfaces/iruntime.h>
#include <project/projectmodel.h>

#include <QJsonObject>
#include <QLoggingCategory>
#include <QProcess>
#include <QtTest>

using namespace KDevelop;

static QString s_testedImage = QStringLiteral("ubuntu:17.04");

class DockerTest: public QObject
{
    Q_OBJECT
public:

    DockerTest() {
        QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.plugins.docker=true\n"));
    }

    IRuntime* m_initialRuntime = nullptr;

private Q_SLOTS:
    void initTestCase() {
        auto ret = QProcess::execute("docker", {"pull", s_testedImage});
        if (ret != 0) {
            QSKIP("Couldn't successfully call docker");
            return;
        }

        AutoTestShell::init({QStringLiteral("kdevdocker"), QStringLiteral("KDevGenericManager")});
        TestCore::initialize();

        m_initialRuntime = ICore::self()->runtimeController()->currentRuntime();

        auto plugin = ICore::self()->pluginController()->loadPlugin("kdevdocker");
        QVERIFY(plugin);

        QSignalSpy spy(plugin, SIGNAL(imagesListed()));
        QVERIFY(spy.wait());

        auto projectPath = QUrl::fromLocalFile(QFINDTESTDATA("testproject/test.kdev4"));
        TestCore::self()->projectController()->openProject(projectPath);
        QSignalSpy spy2(TestCore::self()->projectController(), &IProjectController::projectOpened);
        QVERIFY(spy2.wait());
    }

    void init()
    {
        QVERIFY(ICore::self()->runtimeController()->currentRuntime() == m_initialRuntime);
        const auto& availableRuntimes = ICore::self()->runtimeController()->availableRuntimes();
        for (IRuntime* runtime : availableRuntimes) {
            if (s_testedImage == runtime->name()) {
                ICore::self()->runtimeController()->setCurrentRuntime(runtime);
            }
        }
        QVERIFY(ICore::self()->runtimeController()->currentRuntime() != m_initialRuntime);
    }

    void paths() {
        auto rt = ICore::self()->runtimeController()->currentRuntime();
        QVERIFY(rt);

        const Path root("/");
        const Path hostDir = rt->pathInHost(root);
        QCOMPARE(root, rt->pathInRuntime(hostDir));
    }

    void projectPath() {
        auto rt = ICore::self()->runtimeController()->currentRuntime();
        QVERIFY(rt);
        auto project = ICore::self()->projectController()->projects().first();
        QVERIFY(project);

        const Path file = project->projectItem()->folder()->fileList().first()->path();
        const Path fileRuntime = rt->pathInRuntime(file);
        QCOMPARE(fileRuntime, Path("/src/test/testfile.sh"));
        QCOMPARE(rt->pathInHost(fileRuntime), file);
        QCOMPARE(project->path(), rt->pathInHost(rt->pathInRuntime(project->path())));
    }

    void projectDirectory() {
        auto rt = ICore::self()->runtimeController()->currentRuntime();
        QVERIFY(rt);
        auto project = ICore::self()->projectController()->projects().first();
        QVERIFY(project);

        const Path projectDir = project->path();
        const Path dirRuntime = rt->pathInRuntime(projectDir);
        QCOMPARE(dirRuntime, Path("/src/test/"));
        QCOMPARE(rt->pathInHost(dirRuntime), projectDir);
        QCOMPARE(project->path(), rt->pathInHost(rt->pathInRuntime(project->path())));
    }

    void envs() {
        auto rt = ICore::self()->runtimeController()->currentRuntime();
        QVERIFY(rt);

        QCOMPARE(rt->getenv("PATH"), QByteArray("/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"));
    }

    void runProcess() {
        auto rt = ICore::self()->runtimeController()->currentRuntime();
        QVERIFY(rt);
        auto project = ICore::self()->projectController()->projects().first();
        QVERIFY(project);

        const Path projectPath = rt->pathInRuntime(project->path());
        QProcess process;
        process.setProgram("ls");
        process.setArguments({projectPath.toLocalFile()});
        rt->startProcess(&process);
        QVERIFY(process.waitForFinished());
        QCOMPARE(process.exitCode(), 0);
        QCOMPARE(process.readAll(), QByteArray("test.kdev4\ntestfile.sh\n"));
    }

    void cleanup() {
        ICore::self()->runtimeController()->setCurrentRuntime(m_initialRuntime);
    }

};

QTEST_MAIN( DockerTest )

#include "test_docker.moc"