• 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

53.66
/backend/services/deployments/utils/io.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

15
package utils
16

17
import (
18
        "errors"
19
        "io"
20
)
21

22
var ErrStreamTooLarge = errors.New("read too many bytes")
23

24
type ReadCounter interface {
25
        io.Reader
26
        Count() int64
27
}
28

UNCOV
29
func CountReads(r io.Reader) ReadCounter {
×
UNCOV
30
        if rc, ok := r.(ReadCounter); ok {
×
UNCOV
31
                return rc
×
UNCOV
32
        }
×
UNCOV
33
        return &readCounter{
×
UNCOV
34
                R: r,
×
UNCOV
35
                N: 0,
×
UNCOV
36
        }
×
37
}
38

39
type readCounter struct {
40
        R io.Reader
41
        N int64
42
}
43

UNCOV
44
func (rc *readCounter) Read(b []byte) (int, error) {
×
UNCOV
45
        n, err := rc.R.Read(b)
×
UNCOV
46
        rc.N += int64(n)
×
UNCOV
47
        return n, err
×
UNCOV
48
}
×
49

UNCOV
50
func (rc readCounter) Count() int64 {
×
UNCOV
51
        return rc.N
×
UNCOV
52
}
×
53

54
type limitedReader struct {
55
        R       io.Reader // underlying reader
56
        N       int64     // bytes read
57
        atLeast int64     // expected number of bytes read before reaching EOF
58
        atMost  int64     // maximum number of bytes expected
59
}
60

61
// ReadExactly returns a reader that expects to read exactly size number of
62
// bytes. If io.EOF is returned before reading size bytes, the error is replaced
63
// by io.ErrUnexpectedEOF. Similarly if, the reader reads past size bytes, the
64
// reader replaces the error with ErrStreamTooLarge.
65
func ReadExactly(r io.Reader, size int64) ReadCounter {
1✔
66
        return &limitedReader{
1✔
67
                R:       r,
1✔
68
                atLeast: size,
1✔
69
                atMost:  size,
1✔
70
        }
1✔
71
}
1✔
72

73
// ReadAtMost, like ReadExactly, returns a reader that expects to read at most
74
// size bytes.
75
func ReadAtMost(r io.Reader, size int64) ReadCounter {
1✔
76
        return &limitedReader{
1✔
77
                R:      r,
1✔
78
                atMost: size,
1✔
79
        }
1✔
80
}
1✔
81

82
func (l *limitedReader) Read(p []byte) (n int, err error) {
1✔
83
        n, err = l.R.Read(p)
1✔
84
        l.N += int64(n)
1✔
85
        if l.N > l.atMost {
2✔
86
                err = ErrStreamTooLarge
1✔
87
        } else if err == io.EOF && l.N < l.atLeast {
3✔
88
                err = io.ErrUnexpectedEOF
1✔
89
        }
1✔
90
        return n, err
1✔
91
}
92

UNCOV
93
func (l *limitedReader) Count() int64 {
×
UNCOV
94
        return l.N
×
UNCOV
95
}
×
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