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

mendersoftware / mender-server / 1795862003

01 May 2025 11:44AM UTC coverage: 65.221%. First build
1795862003

Pull #615

gitlab-ci

bahaa-ghazal
feat: Implemented content type checker middleware for gin framework

Ticket: MEN-8327
Changelog: Title
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #615: feat: Implemented content type checker middleware for gin framework

0 of 27 new or added lines in 2 files covered. (0.0%)

31802 of 48760 relevant lines covered (65.22%)

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

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

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

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

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

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

NEW
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