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

mendersoftware / inventory / 1401701972

05 Aug 2024 08:32PM UTC coverage: 91.217%. Remained the same
1401701972

push

gitlab-ci

web-flow
Merge pull request #460 from mendersoftware/dependabot/docker/docker-dependencies-03b04ac819

chore: bump golang from 1.22.4-alpine3.19 to 1.22.5-alpine3.19 in the docker-dependencies group

3095 of 3393 relevant lines covered (91.22%)

148.68 hits per line

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

100.0
/utils/search.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
package utils
15

16
import (
17
        "strings"
18
        "unicode"
19

20
        "github.com/mendersoftware/inventory/model"
21
)
22

23
// Check if string is presnt in an array. Would use interface{} but
24
// whatever.
25
func ContainsString(val string, vals []string) bool {
31✔
26
        for _, v := range vals {
94✔
27
                if val == v {
79✔
28
                        return true
16✔
29
                }
16✔
30
        }
31
        return false
15✔
32
}
33

34
// TextToKeywords converts text to keywords for full-text indexing
35
func TextToKeywords(in string) string {
1,271✔
36
        s := []rune(in)
1,271✔
37
        j := 0
1,271✔
38
        for _, b := range s {
24,208✔
39
                if unicode.IsLetter(b) || unicode.IsDigit(b) {
45,230✔
40
                        s[j] = b
22,293✔
41
                        j++
22,293✔
42
                } else if j > 0 && s[j-1] != ' ' {
23,247✔
43
                        s[j] = ' '
310✔
44
                        j++
310✔
45
                }
310✔
46
        }
47
        return string(s[:j])
1,271✔
48
}
49

50
// GetTextField returns the text field for the given device
51
func GetTextField(device *model.Device) string {
86✔
52
        var text strings.Builder
86✔
53
        text.WriteString(TextToKeywords(device.ID.String()))
86✔
54
        if device.Group.String() != "" {
87✔
55
                text.WriteString(" " + TextToKeywords(device.Group.String()))
1✔
56
        }
1✔
57
        for _, attr := range device.Attributes {
1,281✔
58
                if IsScopeFullText(attr.Scope) {
2,380✔
59
                        if val, _ := attr.Value.(string); val != "" {
2,363✔
60
                                text.WriteString(" " + TextToKeywords(val))
1,178✔
61
                        }
1,178✔
62
                }
63
        }
64
        return text.String()
86✔
65
}
66

67
func IsScopeFullText(scope string) bool {
1,195✔
68
        return scope == model.AttrScopeIdentity ||
1,195✔
69
                scope == model.AttrScopeInventory ||
1,195✔
70
                scope == model.AttrScopeTags
1,195✔
71
}
1,195✔
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