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

mendersoftware / mender-server / 1719679603

17 Mar 2025 08:40AM UTC coverage: 65.521% (+0.02%) from 65.504%
1719679603

Pull #531

gitlab-ci

alfrunes
fix: Skip IoT Core/IoT Hub integration if device is not yet provisioned

If a device has not previously been provisioned, it is not part of the
integration and should be excluded from the sync.

Ticket: MEN-8230
Changelog: Title
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #531: fix: Skip IoT Core/IoT Hub integration if device is not yet provisioned

2 of 6 new or added lines in 1 file covered. (33.33%)

2 existing lines in 1 file now uncovered.

31701 of 48383 relevant lines covered (65.52%)

1.38 hits per line

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

84.62
/backend/services/iot-manager/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
        "errors"
20

21
        "github.com/mendersoftware/mender-server/services/iot-manager/model"
22
        "github.com/mendersoftware/mender-server/services/iot-manager/store"
23

24
        "github.com/google/uuid"
25
)
26

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

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

40
func newDevice(deviceID string, deviceGetter deviceGetter) *device {
3✔
41
        return &device{
3✔
42
                DeviceID:     deviceID,
3✔
43
                DeviceGetter: deviceGetter,
3✔
44
        }
3✔
45
}
3✔
46

47
func (m *device) HasIntegration(ctx context.Context, id uuid.UUID) (bool, error) {
2✔
48
        if m.err != nil {
3✔
49
                if errors.Is(m.err, store.ErrObjectNotFound) {
1✔
NEW
50
                        return false, nil
×
NEW
51
                }
×
52
                return false, m.err
1✔
53
        }
54
        if m.m == nil {
4✔
55
                dev, err := m.DeviceGetter.GetDevice(ctx, m.DeviceID)
2✔
56
                if err != nil {
3✔
57
                        m.err = err
1✔
58
                        if errors.Is(m.err, store.ErrObjectNotFound) {
1✔
NEW
59
                                return false, nil
×
NEW
60
                        }
×
61
                        return false, m.err
1✔
62
                }
63
                m.m = make(map[uuid.UUID]struct{}, len(dev.IntegrationIDs))
2✔
64
                for _, iid := range dev.IntegrationIDs {
4✔
65
                        m.m[iid] = struct{}{}
2✔
66
                }
2✔
67
        }
68
        _, ret := m.m[id]
2✔
69
        return ret, nil
2✔
70
}
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