File: test_workflow.cpp

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (217 lines) | stat: -rw-r--r-- 9,871 bytes parent folder | download
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Copyright Contributors to the DNF5 project.
// Copyright Contributors to the libdnf project.
// SPDX-License-Identifier: GPL-2.0-or-later
//
// This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
//
// Libdnf 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) any later version.
//
// Libdnf 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 libdnf.  If not, see <https://www.gnu.org/licenses/>.


#include "test_workflow.hpp"

#include "../shared/private_accessor.hpp"

#include <libdnf5/common/sack/query_cmp.hpp>
#include <libdnf5/comps/group/package.hpp>
#include <libdnf5/transaction/transaction.hpp>

#include <string>


using namespace libdnf5::transaction;


CPPUNIT_TEST_SUITE_REGISTRATION(TransactionWorkflowTest);

namespace {

// Allows accessing private methods
create_private_getter_template;
create_getter(new_package, &libdnf5::transaction::Transaction::new_package);
create_getter(new_comps_group, &libdnf5::transaction::Transaction::new_comps_group);
create_getter(new_comps_environment, &libdnf5::transaction::Transaction::new_comps_environment);
create_getter(set_releasever, &libdnf5::transaction::Transaction::set_releasever);
create_getter(start, &libdnf5::transaction::Transaction::start);
create_getter(finish, &libdnf5::transaction::Transaction::finish);

create_getter(new_transaction, &libdnf5::transaction::TransactionHistory::new_transaction);

create_getter(set_name, &libdnf5::transaction::Package::set_name);
create_getter(set_epoch, &libdnf5::transaction::Package::set_epoch);
create_getter(set_version, &libdnf5::transaction::Package::set_version);
create_getter(set_release, &libdnf5::transaction::Package::set_release);
create_getter(set_arch, &libdnf5::transaction::Package::set_arch);
create_getter(set_repoid, &libdnf5::transaction::Package::set_repoid);
create_getter(set_action, &libdnf5::transaction::Package::set_action);
create_getter(set_reason, &libdnf5::transaction::Package::set_reason);
create_getter(set_state, &libdnf5::transaction::Package::set_state);

}  //namespace

namespace CompsGroupPrivates {

create_private_getter_template;
create_getter(set_group_id, &libdnf5::transaction::CompsGroup::set_group_id);
create_getter(set_name, &libdnf5::transaction::CompsGroup::set_name);
create_getter(set_translated_name, &libdnf5::transaction::CompsGroup::set_translated_name);
create_getter(set_repoid, &libdnf5::transaction::CompsGroup::set_repoid);
create_getter(set_action, &libdnf5::transaction::CompsGroup::set_action);
create_getter(set_reason, &libdnf5::transaction::CompsGroup::set_reason);
create_getter(new_package, &libdnf5::transaction::CompsGroup::new_package);

}  // namespace CompsGroupPrivates

namespace CompsGroupPackagePrivates {

create_private_getter_template;
create_getter(set_name, &libdnf5::transaction::CompsGroupPackage::set_name);
create_getter(set_installed, &libdnf5::transaction::CompsGroupPackage::set_installed);
create_getter(set_package_type, &libdnf5::transaction::CompsGroupPackage::set_package_type);

}  // namespace CompsGroupPackagePrivates

namespace CompsEnvironmentPrivates {

create_private_getter_template;
create_getter(set_environment_id, &libdnf5::transaction::CompsEnvironment::set_environment_id);
create_getter(set_name, &libdnf5::transaction::CompsEnvironment::set_name);
create_getter(set_translated_name, &libdnf5::transaction::CompsEnvironment::set_translated_name);
create_getter(set_repoid, &libdnf5::transaction::CompsEnvironment::set_repoid);
create_getter(set_action, &libdnf5::transaction::CompsEnvironment::set_action);
create_getter(set_reason, &libdnf5::transaction::CompsEnvironment::set_reason);
create_getter(new_group, &libdnf5::transaction::CompsEnvironment::new_group);

}  // namespace CompsEnvironmentPrivates

namespace CompsEnvironmentGroupPrivates {

create_private_getter_template;
create_getter(set_group_id, &libdnf5::transaction::CompsEnvironmentGroup::set_group_id);
create_getter(set_installed, &libdnf5::transaction::CompsEnvironmentGroup::set_installed);
create_getter(set_group_type, &libdnf5::transaction::CompsEnvironmentGroup::set_group_type);

}  // namespace CompsEnvironmentGroupPrivates

namespace TransactionItemPrivates {

create_private_getter_template;
create_getter(set_state, &libdnf5::transaction::TransactionItem::set_state);

}  // namespace TransactionItemPrivates

void TransactionWorkflowTest::test_default_workflow() {
    auto base = new_base();

    // create an empty Transaction object
    libdnf5::transaction::TransactionHistory history(base->get_weak_ptr());
    auto trans = (history.*get(new_transaction{}))();
    CPPUNIT_ASSERT_EQUAL(TransactionState::STARTED, trans.get_state());

    // set vars
    (trans.*get(set_releasever{}))("26");

    // populate goal
    // resolve dependencies
    // prepare RPM transaction

    // add rpm packages to the transaction

    // bash-4.4.12-5.fc26.x86_64
    auto & rpm_bash = (trans.*get(new_package{}))();
    (rpm_bash.*get(set_name{}))("bash");
    (rpm_bash.*get(set_epoch{}))("0");
    (rpm_bash.*get(set_version{}))("4.4.12");
    (rpm_bash.*get(set_release{}))("5.fc26");
    (rpm_bash.*get(set_arch{}))("x86_64");
    (rpm_bash.*get(set_repoid{}))("base");
    (rpm_bash.*get(set_action{}))(TransactionItemAction::INSTALL);
    (rpm_bash.*get(set_reason{}))(TransactionItemReason::GROUP);

    // systemd-233-6.fc26
    auto & rpm_systemd = (trans.*get(new_package{}))();
    (rpm_systemd.*get(set_name{}))("systemd");
    (rpm_systemd.*get(set_epoch{}))("0");
    (rpm_systemd.*get(set_version{}))("233");
    (rpm_systemd.*get(set_release{}))("6.fc26");
    (rpm_systemd.*get(set_arch{}))("x86_64");
    (rpm_systemd.*get(set_repoid{}))("base");
    (rpm_systemd.*get(set_action{}))(TransactionItemAction::INSTALL);
    (rpm_systemd.*get(set_reason{}))(TransactionItemReason::USER);

    // sysvinit-2.88-14.dsf.fc20
    auto & rpm_sysvinit = (trans.*get(new_package{}))();
    (rpm_sysvinit.*get(set_name{}))("sysvinit");
    (rpm_sysvinit.*get(set_epoch{}))("0");
    (rpm_sysvinit.*get(set_version{}))("2.88");
    (rpm_sysvinit.*get(set_release{}))("14.dsf.fc20");
    (rpm_sysvinit.*get(set_arch{}))("x86_64");
    (rpm_sysvinit.*get(set_repoid{}))("f20");
    (rpm_sysvinit.*get(set_action{}))(TransactionItemAction::REPLACED);
    (rpm_sysvinit.*get(set_reason{}))(TransactionItemReason::USER);

    // TODO(dmach):
    // ti_rpm_sysvinit->addReplacedBy(ti_rpm_systemd);

    // add comps groups to the transaction

    auto & comps_group_core = (trans.*get(new_comps_group{}))();
    (comps_group_core.*get(CompsGroupPrivates::set_group_id{}))("core");
    (comps_group_core.*get(CompsGroupPrivates::set_name{}))("Core");
    (comps_group_core.*get(CompsGroupPrivates::set_translated_name{}))("Úplný základ");
    (comps_group_core.*get(CompsGroupPrivates::set_repoid{}))("");
    (comps_group_core.*get(CompsGroupPrivates::set_action{}))(TransactionItemAction::INSTALL);
    (comps_group_core.*get(CompsGroupPrivates::set_reason{}))(TransactionItemReason::USER);

    auto & core_bash = (comps_group_core.*get(CompsGroupPrivates::new_package{}))();
    (core_bash.*get(CompsGroupPackagePrivates::set_name{}))("bash");
    // When the Goal is resolved, we know if the package is part of the transaction or if it was installed already.
    // Both cases are equal from comps perspective and the group package must be marked as installed.
    // Please note that set_installed() has a completely different meaning than TransactionItemAction::INSTALL.
    (core_bash.*get(CompsGroupPackagePrivates::set_installed{}))(true);
    (core_bash.*get(CompsGroupPackagePrivates::set_package_type{}))(libdnf5::comps::PackageType::MANDATORY);

    // add comps environments to the transaction

    auto & comps_environment_minimal = (trans.*get(new_comps_environment{}))();
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_environment_id{}))("minimal");
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_name{}))("Minimal");
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_translated_name{}))("mmm");
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_repoid{}))("");
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_action{}))(TransactionItemAction::INSTALL);
    (comps_environment_minimal.*get(CompsEnvironmentPrivates::set_reason{}))(TransactionItemReason::USER);

    auto & minimal_core = (comps_environment_minimal.*get(CompsEnvironmentPrivates::new_group{}))();
    (minimal_core.*get(CompsEnvironmentGroupPrivates::set_group_id{}))("core");
    (minimal_core.*get(CompsEnvironmentGroupPrivates::set_installed{}))(true);
    (minimal_core.*get(CompsEnvironmentGroupPrivates::set_group_type{}))(libdnf5::comps::PackageType::MANDATORY);

    // save transaction and all associated transaction items
    (trans.*get(start{}))();

    for (auto & env : trans.get_comps_environments()) {
        (env.*get(TransactionItemPrivates::set_state{}))(TransactionItemState::OK);
    }

    for (auto & grp : trans.get_comps_groups()) {
        (grp.*get(TransactionItemPrivates::set_state{}))(TransactionItemState::OK);
    }

    for (auto & pkg : trans.get_packages()) {
        (pkg.*get(TransactionItemPrivates::set_state{}))(TransactionItemState::OK);
    }

    // finish transaction
    (trans.*get(finish{}))(TransactionState::OK);
    CPPUNIT_ASSERT_EQUAL(TransactionState::OK, trans.get_state());
}