• 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

93.65
/model/filters_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
import (
18
        "fmt"
19

20
        validation "github.com/go-ozzo/ozzo-validation/v4"
21
        "github.com/pkg/errors"
22
)
23

24
type DeploymentsSearchParams struct {
25
        Page          int                          `json:"page"`
26
        PerPage       int                          `json:"per_page"`
27
        Filters       []DeploymentsFilterPredicate `json:"filters"`
28
        Sort          []DeploymentsSortCriteria    `json:"sort"`
29
        Attributes    []DeploymentsSelectAttribute `json:"attributes"`
30
        DeviceIDs     []string                     `json:"device_ids"`
31
        DeploymentIDs []string                     `json:"deployment_ids"`
32
        TenantID      string                       `json:"-"`
33
}
34

35
type DeploymentsFilterPredicate struct {
36
        Attribute string      `json:"attribute" bson:"attribute"`
37
        Type      string      `json:"type" bson:"type"`
38
        Value     interface{} `json:"value" bson:"value"`
39
}
40

41
type DeploymentsSortCriteria struct {
42
        Attribute string `json:"attribute"`
43
        Order     string `json:"order"`
44
}
45

46
type DeploymentsSelectAttribute struct {
47
        Attribute string `json:"attribute" bson:"attribute"`
48
}
49

50
func (sp DeploymentsSearchParams) Validate() error {
14✔
51
        for _, f := range sp.Filters {
24✔
52
                err := f.Validate()
10✔
53
                if err != nil {
12✔
54
                        return err
2✔
55
                }
2✔
56
        }
57

58
        for _, s := range sp.Sort {
21✔
59
                err := validation.ValidateStruct(&s,
9✔
60
                        validation.Field(&s.Attribute, validation.Required),
9✔
61
                        validation.Field(&s.Order,
9✔
62
                                validation.Required, validation.In(validSortOrders...),
9✔
63
                        ),
9✔
64
                )
9✔
65
                if err != nil {
11✔
66
                        return err
2✔
67
                }
2✔
68
        }
69

70
        for _, s := range sp.Attributes {
12✔
71
                err := validation.ValidateStruct(&s,
2✔
72
                        validation.Field(&s.Attribute, validation.Required))
2✔
73
                if err != nil {
2✔
NEW
74
                        return err
×
NEW
75
                }
×
76
        }
77
        return nil
10✔
78
}
79

80
func (f DeploymentsFilterPredicate) Validate() error {
16✔
81
        return validation.ValidateStruct(&f,
16✔
82
                validation.Field(&f.Attribute, validation.Required),
16✔
83
                validation.Field(&f.Type, validation.Required, validation.In(validSelectors...)),
16✔
84
                validation.Field(&f.Value, validation.NotNil))
16✔
85
}
16✔
86

87
// ValueType returns actual type info of the value:
88
// type, is_array, err
89
func (f DeploymentsFilterPredicate) ValueType() (Type, bool, error) {
16✔
90
        isArr := false
16✔
91
        typ := TypeStr
16✔
92

16✔
93
        switch f.Value.(type) {
16✔
94
        case bool:
2✔
95
                typ = TypeBool
2✔
96
        case float64:
2✔
97
                typ = TypeNum
2✔
98
        case string:
2✔
99
                break
2✔
NEW
100
        case []string:
×
NEW
101
                isArr = true
×
102
        case []interface{}:
8✔
103
                isArr = true
8✔
104
                ival := f.Value.([]interface{})
8✔
105
                switch ival[0].(type) {
8✔
106
                case bool:
2✔
107
                        typ = TypeBool
2✔
108
                case float64:
2✔
109
                        typ = TypeNum
2✔
110
                case string:
2✔
111
                        break
2✔
112
                default:
2✔
113
                        return 0, false, errors.New(
2✔
114
                                fmt.Sprintf("unknown attribute value type: %v %T",
2✔
115
                                        ival[0], ival[0]),
2✔
116
                        )
2✔
117
                }
118
        default:
2✔
119
                return 0, false, errors.New(
2✔
120
                        fmt.Sprintf("unknown attribute value type: %v %T",
2✔
121
                                f.Value, f.Value),
2✔
122
                )
2✔
123

124
        }
125

126
        return typ, isArr, nil
12✔
127
}
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