Skip to content

Commit 2b6b814

Browse files
committed
Fix linter errors
1 parent f810151 commit 2b6b814

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

examples/simplehttp/main_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ func TestHealth(t *testing.T) {
3434

3535
app := NewApp(logger, cfg, db)
3636

37-
tReq := test.CreateRequestTester(app.Routes(), test.JsonContentType, http.MethodGet, "/health")
37+
tReq := test.CreateRequestTester(
38+
app.Routes(),
39+
test.JSONContentType,
40+
http.MethodGet,
41+
"/health",
42+
)
3843
rs := tReq.Do(t)
3944

4045
var rsData Health

pkg/communication/http/form.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import (
77
"github.com/gorilla/schema"
88
)
99

10-
//nolint:gochecknoglobals //ok
11-
var decoder = schema.NewDecoder()
12-
var encoder = schema.NewEncoder()
13-
10+
// WriteForm writes the provided data to [url.Values].
1411
func WriteForm(src any) (url.Values, error) {
1512
values := url.Values{}
13+
14+
encoder := schema.NewEncoder()
1615
err := encoder.Encode(src, values)
1716
if err != nil {
1817
return nil, err
@@ -21,12 +20,14 @@ func WriteForm(src any) (url.Values, error) {
2120
return values, nil
2221
}
2322

23+
// ReadForm reads url-encoded form data and assigns this to dst.
2424
func ReadForm(r *http.Request, dst any) error {
2525
err := r.ParseForm()
2626
if err != nil {
2727
return err
2828
}
2929

30+
decoder := schema.NewDecoder()
3031
err = decoder.Decode(dst, r.PostForm)
3132
if err != nil {
3233
return err

pkg/test/api_helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func paginatedEndpointHandler(w http.ResponseWriter, r *http.Request) {
3333
func TestPaginatedEndpointTester(t *testing.T) {
3434
tReq := test.CreateRequestTester(
3535
http.HandlerFunc(paginatedEndpointHandler),
36-
test.JsonContentType,
36+
test.JSONContentType,
3737
http.MethodGet,
3838
"",
3939
)

pkg/test/matrix_tester_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func matrixTestHandler(w http.ResponseWriter, r *http.Request) {
6666
func TestMatrixTester(t *testing.T) {
6767
baseRequest := test.CreateRequestTester(
6868
http.HandlerFunc(matrixTestHandler),
69-
test.JsonContentType,
69+
test.JSONContentType,
7070
http.MethodGet,
7171
"",
7272
)

pkg/test/request.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ import (
1515
httptools "github.com/XDoubleU/essentia/pkg/communication/http"
1616
)
1717

18+
// ContentType is used to set the "Content-Type" header of requests.
19+
// This also has an influence on the encoding of your data.
1820
type ContentType = int
1921

2022
const (
21-
JsonContentType ContentType = iota
22-
FormContentType = iota
23+
// JSONContentType sets the "Content-Type" header to "application/json".
24+
JSONContentType ContentType = iota
25+
// FormContentType sets the "Content-Type" header to
26+
// "application/x-www-form-urlencoded".
27+
FormContentType = iota
2328
)
2429

2530
// A RequestTester is used to test a certain HTTP request.
@@ -103,7 +108,7 @@ func (tReq RequestTester) Do(t *testing.T) *http.Response {
103108

104109
if tReq.data != nil {
105110
switch tReq.contentType {
106-
case JsonContentType:
111+
case JSONContentType:
107112
contentType = "application/json"
108113

109114
var body []byte
@@ -168,12 +173,13 @@ func (tReq RequestTester) Do(t *testing.T) *http.Response {
168173
// Copy creates a copy of a [RequestTester] in order to easily test similar requests.
169174
func (tReq RequestTester) Copy() RequestTester {
170175
return RequestTester{
171-
handler: tReq.handler,
172-
ts: tReq.ts,
173-
method: tReq.method,
174-
path: tReq.path,
175-
data: tReq.data,
176-
query: tReq.query,
177-
cookies: tReq.cookies,
176+
handler: tReq.handler,
177+
ts: tReq.ts,
178+
contentType: tReq.contentType,
179+
method: tReq.method,
180+
path: tReq.path,
181+
data: tReq.data,
182+
query: tReq.query,
183+
cookies: tReq.cookies,
178184
}
179185
}

pkg/test/request_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Test struct {
1515
Key string
1616
}
1717

18-
func testHandlerJson(w http.ResponseWriter, r *http.Request) {
18+
func testHandlerJSON(w http.ResponseWriter, r *http.Request) {
1919
cookie, err := r.Cookie("cookiename")
2020
if err != nil || cookie.Value != "value" {
2121
httptools.ServerErrorResponse(w, r, err)
@@ -41,8 +41,8 @@ func TestRequestTesterJson(t *testing.T) {
4141
}
4242

4343
tReq := test.CreateRequestTester(
44-
http.HandlerFunc(testHandlerJson),
45-
test.JsonContentType,
44+
http.HandlerFunc(testHandlerJSON),
45+
test.JSONContentType,
4646
http.MethodPost,
4747
"/test/%d",
4848
1,
@@ -110,9 +110,15 @@ func TestRequestTesterTestServer(t *testing.T) {
110110
Key: "data",
111111
}
112112

113-
ts := httptest.NewServer(http.HandlerFunc(testHandlerJson))
113+
ts := httptest.NewServer(http.HandlerFunc(testHandlerJSON))
114114

115-
tReq := test.CreateRequestTester(nil, test.JsonContentType, http.MethodGet, "/test/%d", 1)
115+
tReq := test.CreateRequestTester(
116+
nil,
117+
test.JSONContentType,
118+
http.MethodGet,
119+
"/test/%d",
120+
1,
121+
)
116122
tReq.AddCookie(&http.Cookie{Name: "cookiename", Value: "value"})
117123
tReq.SetData(reqData)
118124
tReq.SetTestServer(ts)
@@ -128,7 +134,7 @@ func TestRequestTesterTestServer(t *testing.T) {
128134
}
129135

130136
func TestRequestTesterNoTestServerOrHandler(t *testing.T) {
131-
tReq := test.CreateRequestTester(nil, test.JsonContentType, http.MethodGet, "")
137+
tReq := test.CreateRequestTester(nil, test.JSONContentType, http.MethodGet, "")
132138

133139
assert.PanicsWithValue(
134140
t,

0 commit comments

Comments
 (0)