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

mendersoftware / iot-manager / 1401702106

05 Aug 2024 08:32PM UTC coverage: 87.577%. Remained the same
1401702106

push

gitlab-ci

web-flow
Merge pull request #295 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

3264 of 3727 relevant lines covered (87.58%)

11.44 hits per line

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

100.0
/app/device.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 app
16

17
import (
18
        "context"
19

20
        "github.com/mendersoftware/iot-manager/model"
21

22
        "github.com/google/uuid"
23
)
24

25
type deviceGetter interface {
26
        GetDevice(context.Context, string) (*model.Device, error)
27
}
28

29
// device provides an interface to lazily load the device from the database
30
// only when required.
31
type device struct {
32
        m            map[uuid.UUID]struct{}
33
        err          error
34
        DeviceID     string
35
        DeviceGetter deviceGetter
36
}
37

38
func newDevice(deviceID string, deviceGetter deviceGetter) *device {
26✔
39
        return &device{
26✔
40
                DeviceID:     deviceID,
26✔
41
                DeviceGetter: deviceGetter,
26✔
42
        }
26✔
43
}
26✔
44

45
func (m *device) HasIntegration(ctx context.Context, id uuid.UUID) (bool, error) {
20✔
46
        if m.err != nil {
21✔
47
                return false, m.err
1✔
48
        }
1✔
49
        if m.m == nil {
35✔
50
                dev, err := m.DeviceGetter.GetDevice(ctx, m.DeviceID)
16✔
51
                if err != nil {
18✔
52
                        m.err = err
2✔
53
                        return false, m.err
2✔
54
                }
2✔
55
                m.m = make(map[uuid.UUID]struct{}, len(dev.IntegrationIDs))
14✔
56
                for _, iid := range dev.IntegrationIDs {
31✔
57
                        m.m[iid] = struct{}{}
17✔
58
                }
17✔
59
        }
60
        _, ret := m.m[id]
17✔
61
        return ret, nil
17✔
62
}
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