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

jeffotoni / quick / 311

01 Apr 2025 06:57PM UTC coverage: 51.479% (-0.4%) from 51.88%
311

push

circleci

jaquelineabreu
chore: remove quicktest

3464 of 6729 relevant lines covered (51.48%)

1488.93 hits per line

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

0.0
/quicktest.go
1
package quick
2

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

9
const logDelimiter = "====================="
10

11
// QuickTestReturn defines the interface for handling HTTP test responses.
12
type QuickTestReturn interface {
13
        Body() []byte             // Returns the raw response body as a byte slice.
14
        BodyStr() string          // Returns the response body as a string.
15
        StatusCode() int          // Returns the HTTP status code.
16
        Response() *http.Response // Returns the full HTTP response object.
17
}
18

19
type (
20
        qTest struct {
21
                body       []byte
22
                bodyStr    string
23
                statusCode int
24
                response   *http.Response
25
        }
26

27
        // QuickMockTestServer defines a mock server configuration for testing.
28
        QuickMockTestServer struct {
29
                Client  *http.Client      // HTTP client to interact with the mock server.
30
                Port    int               // Port on which the mock server runs.
31
                URI     string            // The request URI for the test.
32
                Method  string            // The HTTP method (GET, POST, etc.).
33
                Headers map[string]string // Headers to be included in the request.
34
                Body    []byte            // Request body content.
35
        }
36
)
37

38
// createHTTPRequest constructs an HTTP request with the specified method, URI, headers, and body.
39
//
40
// Parameters:
41
//   - method (string): HTTP method (e.g., "GET", "POST").
42
//   - URI (string): The request path (e.g., "/api/test").
43
//   - headers (map[string]string): Headers to include in the request.
44
//   - body ([]byte): The request body content.
45
//
46
// Returns:
47
//   - *http.Request: The constructed HTTP request.
48
//   - error: Any error encountered while creating the request.
49
func createHTTPRequest(method, URI string, headers map[string]string, body []byte) (*http.Request, error) {
×
50
        req, err := http.NewRequest(method, URI, io.NopCloser(bytes.NewBuffer(body)))
×
51
        if err != nil {
×
52
                return nil, err
×
53
        }
×
54
        for key, value := range headers {
×
55
                req.Header.Set(key, value)
×
56
        }
×
57
        return req, nil
×
58
}
59

60
// readResponseBody safely reads and returns the response body as a byte slice.
61
//
62
// Parameters:
63
//   - body (io.ReadCloser): The response body stream.
64
//
65
// Returns:
66
//   - []byte: The content of the response body.
67
//   - error: Any error encountered while reading the body.
68
func readResponseBody(body io.ReadCloser) ([]byte, error) {
×
69
        if body == nil {
×
70
                return nil, nil
×
71
        }
×
72
        defer body.Close()
×
73
        return io.ReadAll(body)
×
74
}
75

76
// logRequestDetails logs the details of an HTTP request.
77
//
78
// This function prints the HTTP method, URI, and body length for debugging purposes.
79
//
80
// Parameters:
81
//   - method (string): The HTTP method used in the request.
82
//   - URI (string): The request path.
83
//   - bodyLen (int): The length of the request body.
84
func logRequestDetails(method, URI string, bodyLen int) {
×
85
        println(logDelimiter)
×
86
        println("Method:", method, "| URI:", URI, "| Body Length:", bodyLen)
×
87
        println(logDelimiter)
×
88
}
×
89

90
// Body returns the raw response body as a byte slice.
91
func (qt *qTest) Body() []byte {
×
92
        return qt.body
×
93
}
×
94

95
// BodyStr returns the response body as a string.
96
func (qt *qTest) BodyStr() string {
×
97
        return qt.bodyStr
×
98
}
×
99

100
// StatusCode returns the HTTP status code of the response.
101
func (qt *qTest) StatusCode() int {
×
102
        return qt.statusCode
×
103
}
×
104

105
// Response returns the full HTTP response object.
106
func (qt *qTest) Response() *http.Response {
×
107
        return qt.response
×
108
}
×
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

© 2026 Coveralls, Inc