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

mendersoftware / reporting / 743020307

pending completion
743020307

Pull #87

gitlab-ci

Fabio Tranchitella
chore(tests): add unit test case for too many terms in nested aggregations
Pull Request #87: MEN-5930: index device deployment objects

825 of 929 new or added lines in 17 files covered. (88.81%)

1 existing line in 1 file now uncovered.

2735 of 3182 relevant lines covered (85.95%)

17.25 hits per line

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

64.47
/model/query_deployments.go
1
// Copyright 2022 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
package model
16

17
func BuildDeploymentsQuery(params DeploymentsSearchParams) (Query, error) {
8✔
18
        query := NewQuery()
8✔
19

8✔
20
        for _, f := range params.Filters {
16✔
21
                fpart, err := getFilterPart(FilterPredicate{
8✔
22
                        Attribute: f.Attribute,
8✔
23
                        Type:      f.Type,
8✔
24
                        Value:     f.Value,
8✔
25
                })
8✔
26
                if err != nil {
8✔
NEW
27
                        return nil, err
×
NEW
28
                }
×
29
                query = fpart.AddTo(query)
8✔
30
        }
31

32
        for _, s := range params.Sort {
13✔
33
                sort := NewDeploymentsSort(s)
5✔
34
                query = sort.AddTo(query)
5✔
35
        }
5✔
36

37
        query = query.WithPage(params.Page, params.PerPage)
8✔
38

8✔
39
        if len(params.Attributes) > 0 {
8✔
NEW
40
                sel := NewDeploymentsSelect(params.Attributes)
×
NEW
41
                query = sel.AddTo(query)
×
NEW
42
        }
×
43

44
        if len(params.DeviceIDs) > 0 {
8✔
NEW
45
                devs := NewDevIDsFilter(params.DeviceIDs)
×
NEW
46
                query = devs.AddTo(query)
×
NEW
47
        }
×
48

49
        return query, nil
8✔
50
}
51

52
type deploymentsSort struct {
53
        attrStr  string
54
        attrNum  string
55
        attrBool string
56
        order    string
57
}
58

59
func NewDeploymentsSort(sc DeploymentsSortCriteria) *deploymentsSort {
5✔
60
        order := sc.Order
5✔
61
        if order == "" {
5✔
NEW
62
                order = SortOrderAsc
×
NEW
63
        }
×
64
        return &deploymentsSort{
5✔
65
                attrStr:  sc.Attribute,
5✔
66
                attrNum:  sc.Attribute,
5✔
67
                attrBool: sc.Attribute,
5✔
68
                order:    order,
5✔
69
        }
5✔
70
}
71

72
func (s *deploymentsSort) AddTo(q Query) Query {
5✔
73
        q = q.
5✔
74
                WithSort(
5✔
75
                        M{
5✔
76
                                s.attrStr: M{
5✔
77
                                        "order":         s.order,
5✔
78
                                        "unmapped_type": "keyword",
5✔
79
                                },
5✔
80
                        },
5✔
81
                ).WithSort(
5✔
82
                M{
5✔
83
                        s.attrNum: M{
5✔
84
                                "order":         s.order,
5✔
85
                                "unmapped_type": "double",
5✔
86
                        },
5✔
87
                },
5✔
88
        )
5✔
89

5✔
90
        return q
5✔
91
}
5✔
92

93
type deploymentsSel struct {
94
        attrs []DeploymentsSelectAttribute
95
}
96

NEW
97
func NewDeploymentsSelect(attrs []DeploymentsSelectAttribute) *deploymentsSel {
×
NEW
98
        return &deploymentsSel{
×
NEW
99
                attrs: attrs,
×
NEW
100
        }
×
NEW
101
}
×
102

NEW
103
func (s *deploymentsSel) AddTo(q Query) Query {
×
NEW
104
        fields := []string{}
×
NEW
105

×
NEW
106
        for _, a := range s.attrs {
×
NEW
107
                fields = append(fields, a.Attribute)
×
NEW
108
        }
×
109

110
        // always include the deployment id
NEW
111
        fields = append(fields, "id")
×
NEW
112

×
NEW
113
        return q.With(map[string]interface{}{
×
NEW
114
                "fields":  fields,
×
NEW
115
                "_source": false,
×
NEW
116
        })
×
117

118
}
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