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

mendersoftware / reporting / 820253733

pending completion
820253733

Pull #125

gitlab-ci

GitHub
Merge pull request #124 from kjaskiewiczz/men-6405
Pull Request #125: align staging with master

11 of 20 new or added lines in 4 files covered. (55.0%)

5 existing lines in 3 files now uncovered.

2815 of 3311 relevant lines covered (85.02%)

17.51 hits per line

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

59.76
/model/query_deployments.go
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
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✔
27
                        return nil, err
×
28
                }
×
29
                query = fpart.AddTo(query)
8✔
30
        }
31

32
        if len(params.DeploymentGroups) > 0 {
8✔
NEW
33
                fpart, err := getFilterPart(FilterPredicate{
×
NEW
34
                        Attribute: FieldNameDeploymentGroups,
×
NEW
35
                        Type:      "$in",
×
NEW
36
                        Value:     params.DeploymentGroups,
×
NEW
37
                })
×
NEW
38
                if err != nil {
×
NEW
39
                        return nil, err
×
NEW
40
                }
×
NEW
41
                query = fpart.AddTo(query)
×
42
        }
43

44
        for _, s := range params.Sort {
13✔
45
                sort := NewDeploymentsSort(s)
5✔
46
                query = sort.AddTo(query)
5✔
47
        }
5✔
48

49
        query = query.WithPage(params.Page, params.PerPage)
8✔
50

8✔
51
        if len(params.Attributes) > 0 {
8✔
52
                sel := NewDeploymentsSelect(params.Attributes)
×
53
                query = sel.AddTo(query)
×
54
        }
×
55

56
        return query, nil
8✔
57
}
58

59
type deploymentsSort struct {
60
        attrStr  string
61
        attrNum  string
62
        attrBool string
63
        order    string
64
}
65

66
func NewDeploymentsSort(sc DeploymentsSortCriteria) *deploymentsSort {
5✔
67
        order := sc.Order
5✔
68
        if order == "" {
5✔
69
                order = SortOrderAsc
×
70
        }
×
71
        return &deploymentsSort{
5✔
72
                attrStr:  sc.Attribute,
5✔
73
                attrNum:  sc.Attribute,
5✔
74
                attrBool: sc.Attribute,
5✔
75
                order:    order,
5✔
76
        }
5✔
77
}
78

79
func (s *deploymentsSort) AddTo(q Query) Query {
5✔
80
        q = q.
5✔
81
                WithSort(
5✔
82
                        M{
5✔
83
                                s.attrStr: M{
5✔
84
                                        "order":         s.order,
5✔
85
                                        "unmapped_type": "keyword",
5✔
86
                                },
5✔
87
                        },
5✔
88
                ).WithSort(
5✔
89
                M{
5✔
90
                        s.attrNum: M{
5✔
91
                                "order":         s.order,
5✔
92
                                "unmapped_type": "double",
5✔
93
                        },
5✔
94
                },
5✔
95
        )
5✔
96

5✔
97
        return q
5✔
98
}
5✔
99

100
type deploymentsSel struct {
101
        attrs []DeploymentsSelectAttribute
102
}
103

104
func NewDeploymentsSelect(attrs []DeploymentsSelectAttribute) *deploymentsSel {
×
105
        return &deploymentsSel{
×
106
                attrs: attrs,
×
107
        }
×
108
}
×
109

110
func (s *deploymentsSel) AddTo(q Query) Query {
×
111
        fields := []string{}
×
112

×
113
        for _, a := range s.attrs {
×
114
                fields = append(fields, a.Attribute)
×
115
        }
×
116

117
        // always include the deployment id
118
        fields = append(fields, "id")
×
119

×
120
        return q.With(map[string]interface{}{
×
121
                "fields":  fields,
×
122
                "_source": false,
×
123
        })
×
124

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