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

mendersoftware / mender-server / 1818801511

15 May 2025 08:19AM UTC coverage: 65.367%. First build
1818801511

Pull #653

gitlab-ci

bahaa-ghazal
refactor: Put MakeTestRequest in dedicated testing package

Utilities for testing should be separate from application code.

Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #653: refactor(inventory): Migrate from ant0nie/go-json-rest to gin-gonic/gin

418 of 481 new or added lines in 7 files covered. (86.9%)

31894 of 48792 relevant lines covered (65.37%)

1.37 hits per line

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

29.03
/backend/pkg/rest.utils/utils.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 rest
16

17
import (
18
        "errors"
19
        "net/http"
20

21
        "github.com/gin-gonic/gin"
22

23
        "github.com/mendersoftware/mender-server/pkg/requestid"
24
)
25

26
func RenderError(c *gin.Context, code int, err error) {
3✔
27
        ctx := c.Request.Context()
3✔
28
        _ = c.Error(err)
3✔
29
        err = &Error{
3✔
30
                Err:       err.Error(),
3✔
31
                RequestID: requestid.FromContext(ctx),
3✔
32
        }
3✔
33
        c.JSON(code, err)
3✔
34
}
3✔
35

NEW
36
func RenderErrorWithMessage(c *gin.Context, code int, err error, apiMessage string) {
×
NEW
37
        ctx := c.Request.Context()
×
NEW
38
        _ = c.Error(err)
×
NEW
39
        err = &Error{
×
NEW
40
                Err:       apiMessage,
×
NEW
41
                RequestID: requestid.FromContext(ctx),
×
NEW
42
        }
×
NEW
43
        c.JSON(code, err)
×
NEW
44
}
×
45

NEW
46
func RenderInternalError(c *gin.Context, err error) {
×
NEW
47
        msg := "internal error"
×
NEW
48
        if err != nil {
×
NEW
49
                RenderErrorWithMessage(c,
×
NEW
50
                        http.StatusInternalServerError,
×
NEW
51
                        err, msg,
×
NEW
52
                )
×
NEW
53
                return
×
NEW
54
        }
×
NEW
55
        RenderError(c,
×
NEW
56
                http.StatusInternalServerError,
×
NEW
57
                errors.New(msg),
×
NEW
58
        )
×
59
}
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