~indicator-applet-developers/ubuntu-app-launch/trunk.17.04

« back to all changes in this revision

Viewing changes to tests/systemd-mock.h

  • Committer: Bileto Bot
  • Author(s): Ted Gould
  • Date: 2017-02-06 16:00:20 UTC
  • mfrom: (257.2.153 reset-units)
  • Revision ID: ci-train-bot@canonical.com-20170206160020-vueltmoslgyd3drz
Reset failed units so they can be tried again (LP: #1655754)

Approved by: Rodney Dawes, unity-api-1-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
                                              "ret = '/'", &error);
141
141
        throwError(error);
142
142
 
 
143
        dbus_test_dbus_mock_object_add_method(mock, managerobj, "ResetFailedUnit", G_VARIANT_TYPE_STRING,
 
144
                                              nullptr, /* ret type */
 
145
                                              "", &error);
 
146
        throwError(error);
 
147
 
143
148
        for (auto& instance : instances)
144
149
        {
145
150
            auto obj = dbus_test_dbus_mock_get_object(mock, instancePath(instance).c_str(),
148
153
            dbus_test_dbus_mock_object_add_property(mock, obj, "MainPID", G_VARIANT_TYPE_UINT32,
149
154
                                                    g_variant_new_uint32(instance.primaryPid), &error);
150
155
            throwError(error);
 
156
            dbus_test_dbus_mock_object_add_property(mock, obj, "Result", G_VARIANT_TYPE_STRING,
 
157
                                                    g_variant_new_string("success"), &error);
 
158
            throwError(error);
151
159
 
152
160
            /* Control Group */
153
161
            auto dir = g_build_filename(controlGroupPath.c_str(), instancePath(instance).c_str(), nullptr);
432
440
        return retval;
433
441
    }
434
442
 
 
443
    std::list<std::string> resetCalls()
 
444
    {
 
445
        guint len = 0;
 
446
        GError* error = nullptr;
 
447
 
 
448
        auto calls = dbus_test_dbus_mock_object_get_method_calls(mock,              /* mock */
 
449
                                                                 managerobj,        /* manager */
 
450
                                                                 "ResetFailedUnit", /* function */
 
451
                                                                 &len,              /* number */
 
452
                                                                 &error             /* error */
 
453
                                                                 );
 
454
 
 
455
        if (error != nullptr)
 
456
        {
 
457
            g_warning("Unable to get 'ResetFailedUnit' calls from systemd mock: %s", error->message);
 
458
            g_error_free(error);
 
459
            throw std::runtime_error{"Mock disfunctional"};
 
460
        }
 
461
 
 
462
        std::list<std::string> retval;
 
463
 
 
464
        for (unsigned int i = 0; i < len; i++)
 
465
        {
 
466
            auto& call = calls[i];
 
467
            gchar* name = nullptr;
 
468
 
 
469
            g_variant_get(call.params, "(&s)", &name);
 
470
 
 
471
            if (name == nullptr)
 
472
            {
 
473
                g_warning("Invalid 'name' on 'ResetFailedUnit' call");
 
474
                continue;
 
475
            }
 
476
 
 
477
            retval.emplace_back(name);
 
478
        }
 
479
 
 
480
        return retval;
 
481
    }
 
482
 
435
483
    void managerClear()
436
484
    {
437
485
        GError* error = nullptr;
478
526
            throw std::runtime_error{"Mock disfunctional"};
479
527
        }
480
528
    }
 
529
 
 
530
    void managerEmitFailed(const Instance& inst)
 
531
    {
 
532
        auto instobj =
 
533
            std::find_if(insts.begin(), insts.end(), [inst](const std::pair<Instance, DbusTestDbusMockObject*>& item) {
 
534
                return item.first.job == inst.job && item.first.appid == inst.appid &&
 
535
                       item.first.instanceid == inst.instanceid;
 
536
            });
 
537
 
 
538
        if (instobj == insts.end())
 
539
        {
 
540
            throw std::runtime_error{"Unable to find instance"};
 
541
        }
 
542
 
 
543
        GError* error = nullptr;
 
544
        dbus_test_dbus_mock_object_update_property(mock, instobj->second, "Result", g_variant_new_string("fail"),
 
545
                                                   &error);
 
546
 
 
547
        if (error != nullptr)
 
548
        {
 
549
            g_warning("Unable to set result to 'fail': %s", error->message);
 
550
            g_error_free(error);
 
551
            throw std::runtime_error{"Mock disfunctional"};
 
552
        }
 
553
    }
481
554
};