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

mendersoftware / mender-server / 1622978334

13 Jan 2025 03:51PM UTC coverage: 72.802% (-3.8%) from 76.608%
1622978334

Pull #300

gitlab-ci

alfrunes
fix: Deployment device count should not exceed max devices

Added a condition to skip deployments when the device count reaches max
devices.

Changelog: Title
Ticket: MEN-7847
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #300: fix: Deployment device count should not exceed max devices

4251 of 6164 branches covered (68.96%)

Branch coverage included in aggregate %.

0 of 18 new or added lines in 1 file covered. (0.0%)

2544 existing lines in 83 files now uncovered.

42741 of 58384 relevant lines covered (73.21%)

21.49 hits per line

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

82.05
/backend/services/deployments/model/device_deployment_log.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
        "fmt"
20
        "time"
21

22
        validation "github.com/go-ozzo/ozzo-validation/v4"
23
        "github.com/go-ozzo/ozzo-validation/v4/is"
24
        "github.com/pkg/errors"
25
)
26

27
var (
28
        ErrInvalidDeploymentLog = errors.New("invalid deployment log")
29
        ErrInvalidLogMessage    = errors.New("invalid log message")
30
)
31

32
type LogMessage struct {
33
        Timestamp *time.Time `json:"timestamp" valid:"required"`
34
        Level     string     `json:"level" valid:"required"`
35
        Message   string     `json:"message" valid:"required"`
36
}
37

38
func (l LogMessage) Validate() error {
1✔
39
        return validation.ValidateStruct(&l,
1✔
40
                validation.Field(&l.Timestamp, validation.Required),
1✔
41
                validation.Field(&l.Level, validation.Required),
1✔
42
                validation.Field(&l.Message, validation.Required),
1✔
43
        )
1✔
44
}
1✔
45

46
func (l *LogMessage) UnmarshalJSON(raw []byte) error {
1✔
47
        type logMessage LogMessage
1✔
48
        if err := json.Unmarshal(raw, (*logMessage)(l)); err != nil {
1✔
49
                return err
×
50
        }
×
51

52
        if err := l.Validate(); err != nil {
2✔
53
                return err
1✔
54
        }
1✔
55
        return nil
1✔
56
}
57

UNCOV
58
func (l LogMessage) String() string {
×
UNCOV
59
        return fmt.Sprintf("%s %s: %s", l.Timestamp.UTC().String(), l.Level, l.Message)
×
UNCOV
60
}
×
61

62
type DeploymentLog struct {
63
        // skip these 2 field when (un)marshaling to/from JSON
64
        DeviceID     string `json:"-" valid:"required"`
65
        DeploymentID string `json:"-" valid:"uuidv4,required"`
66

67
        Messages []LogMessage `json:"messages" valid:"required"`
68
}
69

70
func (d *DeploymentLog) UnmarshalJSON(raw []byte) error {
1✔
71
        type AuxDeploymentLog DeploymentLog
1✔
72

1✔
73
        var adl AuxDeploymentLog
1✔
74

1✔
75
        if err := json.Unmarshal(raw, &adl); err != nil {
1✔
76
                return err
×
77
        }
×
78

79
        if len(adl.Messages) == 0 {
2✔
80
                return errors.Wrapf(ErrInvalidDeploymentLog, "no messages")
1✔
81
        }
1✔
82

83
        d.Messages = adl.Messages
1✔
84
        return nil
1✔
85
}
86

87
func (d DeploymentLog) Validate() error {
1✔
88
        return validation.ValidateStruct(&d,
1✔
89
                validation.Field(&d.DeviceID, validation.Required),
1✔
90
                validation.Field(&d.DeploymentID, validation.Required, is.UUID),
1✔
91
                validation.Field(&d.Messages, validation.Required),
1✔
92
        )
1✔
93
}
1✔
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