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

mendersoftware / mender-server / 1812619803

12 May 2025 09:48AM UTC coverage: 65.361%. First build
1812619803

Pull #653

gitlab-ci

bahaa-ghazal
refactor(inventory): Migrate from ant0nie/go-json-rest to gin-gonic/gin

Ticket: MEN-8236
Changelog: Title
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #653: refactor(inventory): Migrate from ant0nie/go-json-rest to gin-gonic/gin

419 of 483 new or added lines in 8 files covered. (86.75%)

31906 of 48815 relevant lines covered (65.36%)

1.37 hits per line

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

0.0
/backend/pkg/rest.utils/request.go
1
package rest
2

3
import (
4
        "bytes"
5
        "encoding/json"
6
        "io"
7
        "net/http"
8
)
9

10
const DEFAULT_AUTH = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
11
        "eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVuZGVyLnBsYW4iOiJlbnRlcnByaXNlIn0." +
12
        "s27fi93Qik81WyBmDB5APE0DfGko7Pq8BImbp33-gy4"
13

14
type TestRequest struct {
15
        Method      string
16
        Path        string
17
        Body        interface{}
18
        ContentType string
19
        Auth        bool
20
        Token       string
21
}
22

23
func MakeTestRequest(r *TestRequest) *http.Request {
×
24
        var body io.Reader
×
25
        if r.Body != nil {
×
26
                bodyJSON, _ := json.Marshal(r.Body)
×
27
                body = bytes.NewReader(bodyJSON)
×
28
        }
×
29

30
        req, _ := http.NewRequest(r.Method, r.Path, body)
×
31

×
32
        if r.Auth {
×
33
                if r.Token == "" {
×
34
                        req.Header.Set("Authorization", DEFAULT_AUTH)
×
35
                } else {
×
36
                        req.Header.Set("Authorization", r.Token)
×
37
                }
×
38
        }
39

NEW
40
        if r.Body == nil || body == nil {
×
41
                return req
×
42
        }
×
43

44
        if r.ContentType == "" {
×
45
                req.Header.Set("Content-Type", "application/json")
×
46
        } else {
×
47
                req.Header.Set("Content-Type", r.ContentType)
×
48
        }
×
49

50
        return req
×
51
}
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