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

mendersoftware / mender / 1197434403

01 Mar 2024 04:23PM UTC coverage: 75.661% (-0.06%) from 75.716%
1197434403

push

gitlab-ci

vpodzime
chore: Use HeaderView::GetDepends() in ArtifactMatchesContext()

Simplifies the code a bit and tests for ArtifactMatchesContext()
test HeaderView::GetDepends().

Ticket: MEN-6960
Changelog: none
Signed-off-by: Vratislav Podzimek <vratislav.podzimek@northern.tech>

14 of 14 new or added lines in 1 file covered. (100.0%)

8 existing lines in 2 files now uncovered.

7038 of 9302 relevant lines covered (75.66%)

11715.48 hits per line

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

72.73
/src/artifact/artifact.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <artifact/artifact.hpp>
16

17
#include <common/error.hpp>
18
#include <common/expected.hpp>
19

20
#include <artifact/error.hpp>
21

22

23
namespace mender {
24
namespace artifact {
25

26
namespace error = mender::common::error;
27
namespace expected = mender::common::expected;
28

29

30
ExpectedArtifact Parse(io::Reader &reader, config::ParserConfig conf) {
105✔
31
        return parser::Parse(reader, conf);
105✔
32
}
33

34
ExpectedPayloadHeaderView View(parser::Artifact &artifact, size_t index) {
134✔
35
        // Check if the index is available
36
        if (index >= artifact.header.info.payloads.size()) {
134✔
37
                return expected::unexpected(
×
38
                        parser_error::MakeError(parser_error::Code::ParseError, "Payload index out of range"));
×
39
        }
40
        mender::common::json::Json meta_data;
134✔
41
        if (artifact.header.subHeaders.at(index).metadata) {
134✔
42
                meta_data = artifact.header.subHeaders.at(index).metadata.value();
50✔
43
        }
44
        return PayloadHeaderView {
134✔
45
                .version = artifact.version.version,
134✔
46
                .header =
47
                        HeaderView {
48
                                .artifact_group = artifact.header.info.provides.artifact_group.value_or(""),
49
                                .artifact_name = artifact.header.info.provides.artifact_name,
134✔
50
                                .payload_type = artifact.header.info.payloads.at(index).name,
134✔
51
                                .header_info = artifact.header.info,
134✔
52
                                .type_info = artifact.header.subHeaders.at(index).type_info,
134✔
53
                                .meta_data = meta_data,
54
                        },
55
        };
134✔
56
};
57

UNCOV
58
unordered_map<string, string> HeaderView::GetProvides() const {
×
59
        unordered_map<string, string> ret;
UNCOV
60
        ret["artifact_name"] = artifact_name;
×
UNCOV
61
        if (artifact_group != "") {
×
UNCOV
62
                ret["artifact_group"] = artifact_group;
×
63
        }
UNCOV
64
        if (type_info.artifact_provides) {
×
UNCOV
65
                ret.insert(type_info.artifact_provides->cbegin(), type_info.artifact_provides->cend());
×
66
        }
67

UNCOV
68
        return ret;
×
69
}
70

71
unordered_map<string, vector<string>> HeaderView::GetDepends() const {
113✔
72
        unordered_map<string, vector<string>> ret;
73
        ret["device_type"] = header_info.depends.device_type;
339✔
74
        if (header_info.depends.artifact_name) {
113✔
75
                ret["artifact_name"] = header_info.depends.artifact_name.value();
33✔
76
        }
77
        if (header_info.depends.artifact_group) {
113✔
78
                ret["artifact_group"] = header_info.depends.artifact_group.value();
33✔
79
        }
80
        if (type_info.artifact_depends) {
113✔
81
                for (const auto &kv : type_info.artifact_depends.value()) {
13✔
82
                        // type_info.artifact_depends are just <string, string> pairs, we
83
                        // need <string, vector<string>> pairs
84
                        ret[kv.first] = vector<string> {kv.second};
10✔
85
                }
86
        }
87

88
        return ret;
113✔
89
}
90

91
} // namespace artifact
92
} // namespace mender
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

© 2025 Coveralls, Inc