• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KittensBasket / dasboot / 15103039427

19 May 2025 02:37AM UTC coverage: 66.7% (-12.8%) from 79.465%
15103039427

push

github

web-flow
Finally wrote daemon class (#50)

* First becoming of a daemon
(have to comment '-Werror' as it again goes to check build deps)

* Second becoming of a daemon
Add lots of tests (many lack container implementation to work)

193 of 424 branches covered (45.52%)

Branch coverage included in aggregate %.

377 of 536 new or added lines in 3 files covered. (70.34%)

5 existing lines in 1 file now uncovered.

1812 of 2582 relevant lines covered (70.18%)

12.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.36
/dasboot/core/daemon/daemon_ut.cpp
1
#include <gtest/gtest.h>
2

3
#include <iostream>
4

5
#include <dasboot/core/daemon/daemon.hpp>
6
#include <dasboot/cru/os.hpp>
7

8
//TODO(riogor): ALL TESTS IN COMMENTS ARE CURRENTLY FAILING AND BROKEN, BECAUSE OF ABSENCE OF INNER IMPLEMENTATION
9

10
class TDaemonTest : public ::testing::Test
11
{
12
    protected:
13
        NDaemon::TDaemon daemon{"dasboot.sock"};
14

15
    void SetUp() override 
16
    {
22✔
17
    }
22✔
18

19
    void TearDown() override
20
    {
22✔
21
    }
22✔
22

23
    auto GetAndParseRequest()
24
    {
1✔
25
        return daemon.GetAndParseRequest();
1✔
26
    }
1✔
27

28
    auto SendResponse(const NMessages::TResult& response)
NEW
29
    {
×
NEW
30
        daemon.SendResponse(response);
×
NEW
31
    }
×
32

33
        auto DoBuild(const NMessages::TBuildOptions& options)
34
    {
2✔
35
        return daemon.DoBuild(options);
2✔
36
    }
2✔
37

38
        auto DoRun(const NMessages::TRunOptions& options)
39
    {
2✔
40
        return daemon.DoRun(options);
2✔
41
    }
2✔
42

43
        auto DoStart(const NMessages::TStartOptions& options)
44
    {
3✔
45
        return daemon.DoStart(options);
3✔
46
    }
3✔
47

48
        auto DoStop(const NMessages::TStopOptions& options)
49
    {
3✔
50
        return daemon.DoStop(options);
3✔
51
    }
3✔
52

53
        auto DoPs(const NMessages::TPsOptions& options)
54
    {
1✔
55
        return daemon.DoPs(options);
1✔
56
    }
1✔
57

58
        auto DoRm(const NMessages::TRmOptions& options)
59
    {
3✔
60
        return daemon.DoRm(options);
3✔
61
    }
3✔
62

63
        auto DoExec(const NMessages::TExecOptions& options)
64
    {
3✔
65
        return daemon.DoExec(options);
3✔
66
    }
3✔
67

68
        auto DoAttach(const NMessages::TAttachOptions& options)
69
    {
3✔
70
        return daemon.DoAttach(options);
3✔
71
    }
3✔
72
};
73

74
TEST_F(TDaemonTest, DaemonStart)
75
{
1✔
76
        EXPECT_TRUE(NOs::IsPathExists("dasboot.sock"));
1✔
77
}
1✔
78

79
TEST_F(TDaemonTest, DaemonUnknownCommand)
80
{
1✔
81
    zmq::context_t ctx;
1✔
82
    zmq::socket_t sock(ctx, zmq::socket_type::req);
1✔
83
    sock.connect("ipc://" "dasboot.sock");
1✔
84
    sock.send(zmq::buffer("a"), zmq::send_flags::none);    
1✔
85

86
    auto result = GetAndParseRequest();
1✔
87

88
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
89
    EXPECT_EQ(result.text(), "Unknown request");
1✔
90
}
1✔
91

92
TEST_F(TDaemonTest, DaemonBuildCommandByNameCorrect)
93
{
1✔
94
    NMessages::TBuildOptions request;
1✔
95
    request.set_name("a");
1✔
96

97
        auto result = DoBuild(request);
1✔
98

99
        EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
100
        EXPECT_EQ(result.text(), "Not implemented");
1✔
101
}
1✔
102

103
// TEST_F(TDaemonTest, DaemonBuildCommandByNameDuplicate)
104
// {
105
//     NMessages::TBuildOptions request;
106
//     request.set_name("a");
107

108
//     {
109
//         auto result = DoBuild(request);
110

111
//         EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
112
//         EXPECT_EQ(result.text(), "Not implemented");
113
//     }
114

115
//     {
116
//         auto result = DoBuild(request);
117

118
//         EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
119
//         EXPECT_EQ(result.text(), "Container with such name already exists");
120
//     }
121
// }
122

123
TEST_F(TDaemonTest, DaemonBuildCommandNoName)
124
{
1✔
125
    NMessages::TBuildOptions request;
1✔
126

127
    auto result = DoBuild(request);
1✔
128

129
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
130
    EXPECT_EQ(result.text(), "No name given");
1✔
131
}
1✔
132

133
TEST_F(TDaemonTest, DaemonRunCommandByNameCorrect)
134
{
1✔
135
    NMessages::TRunOptions request;
1✔
136
    request.set_name("a");
1✔
137

138
    auto result = DoRun(request);
1✔
139

140
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
141
    EXPECT_EQ(result.text(), "Not implemented");
1✔
142
}
1✔
143

144
// TEST_F(TDaemonTest, DaemonRunCommandByNameDuplicate)
145
// {
146
//     NMessages::TRunOptions request;
147
//     request.set_name("a");
148

149
//     {
150
//         auto result = DoRun(request);
151

152
//         EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
153
//         EXPECT_EQ(result.text(), "Not implemented");
154
//     }
155

156
//     {
157
//         auto result = DoRun(request);
158

159
//         EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
160
//         EXPECT_EQ(result.text(), "Container with such name already exists");
161
//     }
162
// }
163

164
TEST_F(TDaemonTest, DaemonRunCommandNoName)
165
{
1✔
166
    NMessages::TRunOptions request;
1✔
167

168
    auto result = DoRun(request);
1✔
169

170
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
171
    EXPECT_EQ(result.text(), "No name given");
1✔
172
}
1✔
173

174
// TEST_F(TDaemonTest, DaemonStartCommandByNameCorrect)
175
// {
176
//     NMessages::TStartOptions request;
177
//     request.set_name("a");
178

179
//     auto result = DoStart(request);
180

181
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
182
//     EXPECT_EQ(result.text(), "Not implemented");
183
// }
184

185
TEST_F(TDaemonTest, DaemonStartCommandNoContainerWithName)
186
{
1✔
187
    NMessages::TStartOptions request;
1✔
188
    request.set_name("a");
1✔
189

190
    auto result = DoStart(request);
1✔
191

192
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
193
    EXPECT_EQ(result.text(), "No container with such name");
1✔
194
}
1✔
195

196
// TEST_F(TDaemonTest, DaemonStartCommandByIdCorrect)
197
// {
198
//     NMessages::TStartOptions request;
199
//     request.set_id("1");
200

201
//     auto result = DoStart(request);
202

203
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
204
//     EXPECT_EQ(result.text(), "Not implemented");
205
// }
206

207
TEST_F(TDaemonTest, DaemonStartCommandNoContainerWithId)
208
{
1✔
209
    NMessages::TStartOptions request;
1✔
210
    request.set_id("1");
1✔
211

212
    auto result = DoStart(request);
1✔
213

214
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
215
    EXPECT_EQ(result.text(), "No container with such id");
1✔
216
}
1✔
217

218
TEST_F(TDaemonTest, DaemonStartCommandNoNameNoId)
219
{
1✔
220
    NMessages::TStartOptions request;
1✔
221

222
    auto result = DoStart(request);
1✔
223

224
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
225
    EXPECT_EQ(result.text(), "No name or id given");
1✔
226
}
1✔
227

228
// TEST_F(TDaemonTest, DaemonStopCommandByNameCorrect)
229
// {
230
//     NMessages::TStopOptions request;
231
//     request.set_name("a");
232

233
//     auto result = DoStop(request);
234

235
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
236
//     EXPECT_EQ(result.text(), "Not implemented");
237
// }
238

239
TEST_F(TDaemonTest, DaemonStopCommandNoContainerWithName)
240
{
1✔
241
    NMessages::TStopOptions request;
1✔
242
    request.set_name("a");
1✔
243

244
    auto result = DoStop(request);
1✔
245

246
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
247
    EXPECT_EQ(result.text(), "No container with such name");
1✔
248
}
1✔
249

250
// TEST_F(TDaemonTest, DaemonStopCommandByIdCorrect)
251
// {
252
//     NMessages::TStopOptions request;
253
//     request.set_id("0");
254

255
//     auto result = DoStop(request);
256

257
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
258
//     EXPECT_EQ(result.text(), "Not implemented");
259
// }
260

261
TEST_F(TDaemonTest, DaemonStopCommandNoContainerWithId)
262
{
1✔
263
    NMessages::TStopOptions request;
1✔
264
    request.set_id("1");
1✔
265

266
    auto result = DoStop(request);
1✔
267

268
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
269
    EXPECT_EQ(result.text(), "No container with such id");
1✔
270
}
1✔
271

272
TEST_F(TDaemonTest, DaemonStopCommandNoNameNoId)
273
{
1✔
274
    NMessages::TStopOptions request;
1✔
275

276
    auto result = DoStop(request);
1✔
277

278
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
279
    EXPECT_EQ(result.text(), "No name or id given");
1✔
280
}
1✔
281

282
TEST_F(TDaemonTest, DaemonPsCommand)
283
{
1✔
284
    NMessages::TPsOptions request;
1✔
285

286
    auto result = DoPs(request);
1✔
287

288
    EXPECT_EQ(result.code(), NMessages::ReturnCode::SUCESS);
1✔
289
    EXPECT_EQ(result.text(), "");
1✔
290
}
1✔
291

292
// TEST_F(TDaemonTest, DaemonRmCommandByNameCorrect)
293
// {
294
//     NMessages::TRmOptions request;
295
//     request.set_name("a");
296

297
//     auto result = DoRm(request);
298

299
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
300
//     EXPECT_EQ(result.text(), "Not implemented");
301
// }
302

303
TEST_F(TDaemonTest, DaemonRmCommandNoContainerWithName)
304
{
1✔
305
    NMessages::TRmOptions request;
1✔
306
    request.set_name("a");
1✔
307

308
    auto result = DoRm(request);
1✔
309

310
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
311
    EXPECT_EQ(result.text(), "No container with such name");
1✔
312
}
1✔
313

314
// TEST_F(TDaemonTest, DaemonRmCommandByIdCorrect)
315
// {
316
//     NMessages::TRmOptions request;
317
//     request.set_id("0");
318

319
//     auto result = DoRm(request);
320

321
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
322
//     EXPECT_EQ(result.text(), "Not implemented");
323
// }
324

325
TEST_F(TDaemonTest, DaemonRmCommandNoContainerWithId)
326
{
1✔
327
    NMessages::TRmOptions request;
1✔
328
    request.set_id("1");
1✔
329

330
    auto result = DoRm(request);
1✔
331

332
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
333
    EXPECT_EQ(result.text(), "No container with such id");
1✔
334
}
1✔
335

336
TEST_F(TDaemonTest, DaemonRmCommandNoNameNoId)
337
{
1✔
338
    NMessages::TRmOptions request;
1✔
339

340
    auto result = DoRm(request);
1✔
341

342
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
343
    EXPECT_EQ(result.text(), "No name or id given");
1✔
344
}
1✔
345

346
// TEST_F(TDaemonTest, DaemonExecCommandByNameCorrect)
347
// {
348
//     NMessages::TExecOptions request;
349
//     request.set_name("a");
350

351
//     auto result = DoExec(request);
352

353
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
354
//     EXPECT_EQ(result.text(), "Not implemented");
355
// }
356

357
TEST_F(TDaemonTest, DaemonExecCommandNoContainerWithName)
358
{
1✔
359
    NMessages::TExecOptions request;
1✔
360
    request.set_name("a");
1✔
361

362
    auto result = DoExec(request);
1✔
363

364
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
365
    EXPECT_EQ(result.text(), "No container with such name");
1✔
366
}
1✔
367

368
// TEST_F(TDaemonTest, DaemonExecCommandByIdCorrect)
369
// {
370
//     NMessages::TExecOptions request;
371
//     request.set_id("0");
372

373
//     auto result = DoExec(request);
374

375
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
376
//     EXPECT_EQ(result.text(), "Not implemented");
377
// }
378

379
TEST_F(TDaemonTest, DaemonExecCommandNoContainerWithId)
380
{
1✔
381
    NMessages::TExecOptions request;
1✔
382
    request.set_id("1");
1✔
383

384
    auto result = DoExec(request);
1✔
385

386
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
387
    EXPECT_EQ(result.text(), "No container with such id");
1✔
388
}
1✔
389

390
TEST_F(TDaemonTest, DaemonExecCommandNoNameNoId)
391
{
1✔
392
    NMessages::TExecOptions request;
1✔
393

394
    auto result = DoExec(request);
1✔
395

396
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
397
    EXPECT_EQ(result.text(), "No name or id given");
1✔
398
}
1✔
399

400
// TEST_F(TDaemonTest, DaemonAttachCommandByNameCorrect)
401
// {
402
//     NMessages::TAttachOptions request;
403
//     request.set_name("a");
404

405
//     auto result = DoAttach(request);
406

407
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
408
//     EXPECT_EQ(result.text(), "Not implemented");
409
// }
410

411
TEST_F(TDaemonTest, DaemonAttachCommandNoContainerWithName)
412
{
1✔
413
    NMessages::TAttachOptions request;
1✔
414
    request.set_name("a");
1✔
415

416
    auto result = DoAttach(request);
1✔
417

418
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
419
    EXPECT_EQ(result.text(), "No container with such name");
1✔
420
}
1✔
421

422
// TEST_F(TDaemonTest, DaemonAttachCommandByIdCorrect)
423
// {
424
//     NMessages::TAttachOptions request;
425
//     request.set_id("0");
426

427
//     auto result = DoAttach(request);
428

429
//     EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
430
//     EXPECT_EQ(result.text(), "Not implemented");
431
// }
432

433
TEST_F(TDaemonTest, DaemonAttachCommandNoContainerWithId)
434
{
1✔
435
    NMessages::TAttachOptions request;
1✔
436
    request.set_id("1");
1✔
437

438
    auto result = DoAttach(request);
1✔
439

440
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
441
    EXPECT_EQ(result.text(), "No container with such id");
1✔
442
}
1✔
443

444
TEST_F(TDaemonTest, DaemonAttachCommandNoNameNoId)
445
{
1✔
446
    NMessages::TAttachOptions request;
1✔
447

448
    auto result = DoAttach(request);
1✔
449

450
    EXPECT_EQ(result.code(), NMessages::ReturnCode::ERROR);
1✔
451
    EXPECT_EQ(result.text(), "No name or id given");
1✔
452

453
}
1✔
454

455
int main(int argc, char **argv)
456
{
68✔
457
        ::testing::InitGoogleTest(&argc, argv);
68✔
458
        auto result = RUN_ALL_TESTS();
68✔
459
        return result;
68✔
460
}
68✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc