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

mendersoftware / mender-server / 1495380963

14 Oct 2024 03:35PM UTC coverage: 70.373% (-2.5%) from 72.904%
1495380963

Pull #101

gitlab-ci

mineralsfree
feat: tenant list added

Ticket: MEN-7568
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #101: feat: tenant list added

4406 of 6391 branches covered (68.94%)

Branch coverage included in aggregate %.

88 of 183 new or added lines in 10 files covered. (48.09%)

2623 existing lines in 65 files now uncovered.

36673 of 51982 relevant lines covered (70.55%)

31.07 hits per line

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

71.11
/backend/services/deviceconfig/model/attribute.go
1
// Copyright 2021 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
        "encoding/json"
19

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

23
type Attribute struct {
24
        Key   string      `json:"key" bson:"key"`
25
        Value interface{} `json:"value" bson:"value"`
26
}
27

28
func (attr Attribute) Validate() error {
1✔
29
        return validation.ValidateStruct(&attr,
1✔
30
                validation.Field(&attr.Key,
1✔
31
                        validation.Required,
1✔
32
                        lengthLessThan4096,
1✔
33
                ),
1✔
34
                validation.Field(&attr.Value,
1✔
35
                        validateAttributeValue,
1✔
36
                        lengthLessThan4096,
1✔
37
                ),
1✔
38
        )
1✔
39
}
1✔
40

41
type Attributes []Attribute
42

43
func (a Attributes) Validate() error {
1✔
44
        return validation.Validate([]Attribute(a), validateAttributesLength)
1✔
45
}
1✔
46

47
func map2Attributes(configurationMap map[string]interface{}) Attributes {
1✔
48
        attributes := make(Attributes, len(configurationMap))
1✔
49
        i := 0
1✔
50
        for k, v := range configurationMap {
2✔
51
                attributes[i] = Attribute{
1✔
52
                        Key:   k,
1✔
53
                        Value: v,
1✔
54
                }
1✔
55
                i++
1✔
56
        }
1✔
57

58
        return attributes
1✔
59
}
60

UNCOV
61
func (a *Attributes) UnmarshalJSON(b []byte) error {
×
UNCOV
62
        var m map[string]interface{}
×
UNCOV
63

×
UNCOV
64
        err := json.Unmarshal(b, &m)
×
UNCOV
65
        if err != nil {
×
66
                return err
×
67
        }
×
68

UNCOV
69
        *a = map2Attributes(m)
×
UNCOV
70

×
UNCOV
71
        return nil
×
72
}
73

74
func attributes2Map(attributes []Attribute) map[string]interface{} {
1✔
75
        configurationMap := make(map[string]interface{}, len(attributes))
1✔
76
        for _, a := range attributes {
2✔
77
                configurationMap[a.Key] = a.Value.(string)
1✔
78
        }
1✔
79

80
        return configurationMap
1✔
81
}
82

UNCOV
83
func (a Attributes) MarshalJSON() ([]byte, error) {
×
UNCOV
84
        return json.Marshal(attributes2Map(a))
×
UNCOV
85
}
×
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