Skip to content

Commit eedfe1e

Browse files
committed
fix(newrelic): golangci-lint
- error wrapping %w - http.NoBody over nil - unused parameter 'r' - assert errors with require
1 parent 549e609 commit eedfe1e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pkg/services/newrelic.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ func (s newrelicService) getApplicationId(client *http.Client, appName string) (
137137
q.Set("filter[name]", appName)
138138
u.RawQuery = q.Encode()
139139

140-
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
140+
req, err := http.NewRequest(http.MethodGet, u.String(), http.NoBody)
141141
if err != nil {
142-
return "", fmt.Errorf("Failed to create filtered application request: %s", err)
142+
return "", fmt.Errorf("failed to create filtered application request: %w", err)
143143
}
144144

145145
req.Header.Set("Content-Type", "application/json")
@@ -153,7 +153,7 @@ func (s newrelicService) getApplicationId(client *http.Client, appName string) (
153153

154154
var data newrelicApplicationsResponse
155155
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
156-
return "", fmt.Errorf("Failed to decode applications response: %s", err)
156+
return "", fmt.Errorf("failed to decode applications response: %w", err)
157157
}
158158

159159
if len(data.Applications) == 0 {
@@ -199,7 +199,7 @@ func (s newrelicService) Send(notification Notification, dest Destination) (err
199199
return err
200200
}
201201

202-
var appId = dest.Recipient
202+
appId := dest.Recipient
203203
if dest.Recipient != "" {
204204
_, err := strconv.Atoi(dest.Recipient)
205205
if err != nil {

pkg/services/newrelic_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ func TestSend_Newrelic(t *testing.T) {
220220
Recipient: "myapp",
221221
})
222222

223-
if !assert.NoError(t, err) {
224-
t.FailNow()
225-
}
223+
require.NoError(t, err)
226224
})
227225

228226
t.Run("missing config", func(t *testing.T) {
@@ -280,12 +278,12 @@ func TestGetApplicationId(t *testing.T) {
280278
ApiURL: ts.URL,
281279
}).(*newrelicService)
282280
appId, err := service.getApplicationId(http.DefaultClient, "myapp")
283-
assert.NoError(t, err)
281+
require.NoError(t, err)
284282
assert.Equal(t, "123456789", appId)
285283
})
286284

287285
t.Run("application not found", func(t *testing.T) {
288-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
286+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
289287
_, err := w.Write([]byte(`{"applications": []}`))
290288
if !assert.NoError(t, err) {
291289
t.FailNow()
@@ -301,7 +299,7 @@ func TestGetApplicationId(t *testing.T) {
301299
})
302300

303301
t.Run("multiple matches for application name", func(t *testing.T) {
304-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
302+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
305303
_, err := w.Write([]byte(`{
306304
"applications": [
307305
{"id": "123456789"},

0 commit comments

Comments
 (0)