• 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

0.0
/backend/pkg/routing/routing.go
1
// Copyright 2024 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 routing
15

16
import (
17
        "net/http"
18

19
        "github.com/ant0ine/go-json-rest/rest"
20

21
        "github.com/mendersoftware/mender-server/pkg/strings"
22
)
23

24
type HttpOptionsGenerator func(methods []string) rest.HandlerFunc
25

UNCOV
26
func AllowHeaderOptionsGenerator(methods []string) rest.HandlerFunc {
×
UNCOV
27
        // return a dummy handler for now
×
UNCOV
28
        return func(w rest.ResponseWriter, r *rest.Request) {
×
29
                for _, m := range methods {
×
30
                        w.Header().Add("Allow", m)
×
31
                }
×
32
        }
33
}
34

UNCOV
35
func supportsMethod(method string, methods []string) bool {
×
UNCOV
36
        return strings.ContainsString(method, methods)
×
UNCOV
37
}
×
38

39
// Automatically add OPTIONS method support for each defined route,
40
// only if there's no OPTIONS handler for that route yet
UNCOV
41
func AutogenOptionsRoutes(routes []*rest.Route, gen HttpOptionsGenerator) []*rest.Route {
×
UNCOV
42

×
UNCOV
43
        methodGroups := make(map[string][]string, len(routes))
×
UNCOV
44

×
UNCOV
45
        for _, route := range routes {
×
UNCOV
46
                methods, ok := methodGroups[route.PathExp]
×
UNCOV
47
                if !ok {
×
UNCOV
48
                        methods = make([]string, 0)
×
UNCOV
49
                }
×
50

UNCOV
51
                methodGroups[route.PathExp] = append(methods, route.HttpMethod)
×
52
        }
53

UNCOV
54
        options := make([]*rest.Route, 0, len(methodGroups))
×
UNCOV
55
        for route, methods := range methodGroups {
×
UNCOV
56
                // skip if there's a handler for OPTIONS already
×
UNCOV
57
                if !supportsMethod(http.MethodOptions, methods) {
×
UNCOV
58
                        options = append(options,
×
UNCOV
59
                                rest.Options(route, gen(methods)))
×
UNCOV
60
                }
×
61
        }
62

UNCOV
63
        return append(routes, options...)
×
64
}
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