Skip to content

Commit 9c0020c

Browse files
authored
chore: Run formatter over all Go files after the linter change last week (#2382)
* chore: Run formatter over all Go files after the linter change last week * fix: few random refactors (#2379) Just a few small things/nits I've seen.
1 parent 4836563 commit 9c0020c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+593
-173
lines changed

backend/pkg/httpserver/create_saved_search.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ var (
4646
errQueryDoesNotMatchGrammar = errors.New("query does not match grammar")
4747
)
4848

49-
type fieldValidationErrors struct {
50-
fieldErrorMap map[string]string
51-
}
52-
53-
func (f *fieldValidationErrors) addFieldError(field string, err error) {
54-
if f.fieldErrorMap == nil {
55-
f.fieldErrorMap = make(map[string]string)
56-
}
57-
f.fieldErrorMap[field] = err.Error()
58-
}
59-
60-
func (f fieldValidationErrors) hasErrors() bool {
61-
return len(f.fieldErrorMap) > 0
62-
}
63-
6449
// validateSavedSearchName checks the validity of the saved search name.
6550
// It expects a pointer to handle potential nil values during updates.
6651
func validateSavedSearchName(name *string, fieldErrors *fieldValidationErrors) {

backend/pkg/httpserver/delete_notification_channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func (s *Server) DeleteNotificationChannel(
4242

4343
err := s.wptMetricsStorer.DeleteNotificationChannel(ctx, userCheckResult.User.ID, req.ChannelId)
4444
if err != nil {
45-
if errors.Is(err, backendtypes.ErrEntityDoesNotExist) || errors.Is(err, backendtypes.ErrUserNotAuthorizedForAction) {
45+
if errors.Is(err, backendtypes.ErrEntityDoesNotExist) ||
46+
errors.Is(err, backendtypes.ErrUserNotAuthorizedForAction) {
4647
return backend.DeleteNotificationChannel404JSONResponse{
4748
Code: http.StatusNotFound,
4849
Message: "Notification channel not found or not owned by user",

backend/pkg/httpserver/get_feature_metadata_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ func TestGetFeatureMetadata(t *testing.T) {
5454
},
5555
err: nil,
5656
},
57-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/key1/feature-metadata", nil),
57+
request: httptest.NewRequestWithContext(
58+
t.Context(),
59+
http.MethodGet,
60+
"/v1/features/key1/feature-metadata",
61+
nil,
62+
),
5863
expectedGetCalls: []*ExpectedGetCall{
5964
{
6065
Key: `getFeatureMetadata-{"feature_id":"key1"}`,
@@ -83,7 +88,12 @@ func TestGetFeatureMetadata(t *testing.T) {
8388
result: nil,
8489
err: nil,
8590
},
86-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/key1/feature-metadata", nil),
91+
request: httptest.NewRequestWithContext(
92+
t.Context(),
93+
http.MethodGet,
94+
"/v1/features/key1/feature-metadata",
95+
nil,
96+
),
8797
expectedGetCalls: []*ExpectedGetCall{
8898
{
8999
Key: `getFeatureMetadata-{"feature_id":"key1"}`,
@@ -112,7 +122,10 @@ func TestGetFeatureMetadata(t *testing.T) {
112122
t: t,
113123
}
114124
mockCacher := NewMockRawBytesDataCacher(t, tc.expectedCacheCalls, tc.expectedGetCalls)
115-
myServer := Server{wptMetricsStorer: mockStorer, metadataStorer: mockMetadataStorer, userGitHubClientFactory: nil,
125+
myServer := Server{
126+
wptMetricsStorer: mockStorer,
127+
metadataStorer: mockMetadataStorer,
128+
userGitHubClientFactory: nil,
116129
operationResponseCaches: initOperationResponseCaches(mockCacher, getTestRouteCacheOptions()),
117130
baseURL: getTestBaseURL(t),
118131
eventPublisher: nil,

backend/pkg/httpserver/get_feature_test.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ func TestGetFeature(t *testing.T) {
8585
err: nil,
8686
},
8787
expectedCallCount: 1,
88-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
88+
request: httptest.NewRequestWithContext(
89+
t.Context(),
90+
http.MethodGet,
91+
"/v1/features/feature1",
92+
nil,
93+
),
8994
expectedGetCalls: []*ExpectedGetCall{
9095
{
9196
Key: `getFeature-{"feature_id":"feature1","Params":{}}`,
@@ -129,7 +134,12 @@ func TestGetFeature(t *testing.T) {
129134
name: "Success Case - no optional params - use defaults - cached",
130135
mockConfig: nil,
131136
expectedCallCount: 0,
132-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
137+
request: httptest.NewRequestWithContext(
138+
t.Context(),
139+
http.MethodGet,
140+
"/v1/features/feature1",
141+
nil,
142+
),
133143
expectedGetCalls: []*ExpectedGetCall{
134144
{
135145
Key: `getFeature-{"feature_id":"feature1","Params":{}}`,
@@ -319,8 +329,13 @@ func TestGetFeature(t *testing.T) {
319329
err: gcpspanner.ErrQueryReturnedNoResults,
320330
},
321331
expectedCallCount: 1,
322-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
323-
expectedResponse: testJSONResponse(404, `{"code":404,"message":"feature id feature1 is not found"}`),
332+
request: httptest.NewRequestWithContext(
333+
t.Context(),
334+
http.MethodGet,
335+
"/v1/features/feature1",
336+
nil,
337+
),
338+
expectedResponse: testJSONResponse(404, `{"code":404,"message":"feature id feature1 is not found"}`),
324339
expectedGetCalls: []*ExpectedGetCall{
325340
{
326341
Key: `getFeature-{"feature_id":"feature1","Params":{}}`,
@@ -340,8 +355,13 @@ func TestGetFeature(t *testing.T) {
340355
err: errTest,
341356
},
342357
expectedCallCount: 1,
343-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
344-
expectedResponse: testJSONResponse(500, `{"code":500,"message":"unable to get feature"}`),
358+
request: httptest.NewRequestWithContext(
359+
t.Context(),
360+
http.MethodGet,
361+
"/v1/features/feature1",
362+
nil,
363+
),
364+
expectedResponse: testJSONResponse(500, `{"code":500,"message":"unable to get feature"}`),
345365
expectedGetCalls: []*ExpectedGetCall{
346366
{
347367
Key: `getFeature-{"feature_id":"feature1","Params":{}}`,
@@ -361,7 +381,12 @@ func TestGetFeature(t *testing.T) {
361381
err: nil,
362382
},
363383
expectedCallCount: 1,
364-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
384+
request: httptest.NewRequestWithContext(
385+
t.Context(),
386+
http.MethodGet,
387+
"/v1/features/feature1",
388+
nil,
389+
),
365390
expectedResponse: func() *http.Response {
366391
// nolint:exhaustruct
367392
return &http.Response{
@@ -400,7 +425,12 @@ func TestGetFeature(t *testing.T) {
400425
err: nil,
401426
},
402427
expectedCallCount: 1,
403-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features/feature1", nil),
428+
request: httptest.NewRequestWithContext(
429+
t.Context(),
430+
http.MethodGet,
431+
"/v1/features/feature1",
432+
nil,
433+
),
404434
expectedResponse: testJSONResponse(410, `
405435
{"code":410,"message":"feature is split","new_features":[{"id":"other1"},{"id":"other2"}],"type":"split"}`,
406436
),

backend/pkg/httpserver/get_features_test.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,16 @@ func TestListFeatures(t *testing.T) {
337337
}
338338
}`,
339339
),
340-
request: httptest.NewRequestWithContext(t.Context(),
340+
request: httptest.NewRequestWithContext(
341+
t.Context(),
341342
http.MethodGet,
342-
fmt.Sprintf("/v1/features?page_token=%s&page_size=50&q=%s&sort=name_desc&wpt_metric_view=subtest_counts",
343+
fmt.Sprintf(
344+
"/v1/features?page_token=%s&page_size=50&q=%s&sort=name_desc&wpt_metric_view=subtest_counts",
343345
*inputPageToken,
344346
url.QueryEscape("available_on:chrome AND name:grid"),
345347
),
346-
nil),
348+
nil,
349+
),
347350
},
348351
{
349352
name: "Success Case - include optional params - cached",
@@ -403,13 +406,16 @@ func TestListFeatures(t *testing.T) {
403406
}
404407
}`,
405408
),
406-
request: httptest.NewRequestWithContext(t.Context(),
409+
request: httptest.NewRequestWithContext(
410+
t.Context(),
407411
http.MethodGet,
408-
fmt.Sprintf("/v1/features?page_token=%s&page_size=50&q=%s&sort=name_desc&wpt_metric_view=subtest_counts",
412+
fmt.Sprintf(
413+
"/v1/features?page_token=%s&page_size=50&q=%s&sort=name_desc&wpt_metric_view=subtest_counts",
409414
*inputPageToken,
410415
url.QueryEscape("available_on:chrome AND name:grid"),
411416
),
412-
nil),
417+
nil,
418+
),
413419
},
414420
{
415421
name: "500 case",
@@ -495,7 +501,12 @@ func TestListFeatures(t *testing.T) {
495501
expectedResponse: testJSONResponse(400,
496502
`{"code":400,"message":"query string cannot be decoded"}`,
497503
),
498-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features?q="+url.QueryEscape("%"), nil),
504+
request: httptest.NewRequestWithContext(
505+
t.Context(),
506+
http.MethodGet,
507+
"/v1/features?q="+url.QueryEscape("%"),
508+
nil,
509+
),
499510
},
500511
{
501512
name: "400 case - invalid page token",
@@ -529,7 +540,12 @@ func TestListFeatures(t *testing.T) {
529540
expectedResponse: testJSONResponse(400,
530541
`{"code":400,"message":"invalid page token"}`,
531542
),
532-
request: httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/features?page_token="+*badPageToken, nil),
543+
request: httptest.NewRequestWithContext(
544+
t.Context(),
545+
http.MethodGet,
546+
"/v1/features?page_token="+*badPageToken,
547+
nil,
548+
),
533549
},
534550
}
535551
for _, tc := range testCases {

backend/pkg/httpserver/get_notification_channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func (s *Server) GetNotificationChannel(
4242

4343
channel, err := s.wptMetricsStorer.GetNotificationChannel(ctx, userCheckResult.User.ID, req.ChannelId)
4444
if err != nil {
45-
if errors.Is(err, backendtypes.ErrEntityDoesNotExist) || errors.Is(err, backendtypes.ErrUserNotAuthorizedForAction) {
45+
if errors.Is(err, backendtypes.ErrEntityDoesNotExist) ||
46+
errors.Is(err, backendtypes.ErrUserNotAuthorizedForAction) {
4647
return backend.GetNotificationChannel404JSONResponse{
4748
Code: http.StatusNotFound,
4849
Message: "Notification channel not found or not owned by user",

backend/pkg/httpserver/list_aggregated_wpt_metrics_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,13 @@ func TestListAggregatedWPTMetrics(t *testing.T) {
304304
eventPublisher: nil,
305305
baseURL: getTestBaseURL(t)}
306306
assertTestServerRequest(t, &myServer, tc.request, tc.expectedResponse)
307-
assertMocksExpectations(t, tc.expectedCallCount, mockStorer.callCountListMetricsOverTimeWithAggregatedTotals,
308-
"ListMetricsOverTimeWithAggregatedTotals", mockCacher)
307+
assertMocksExpectations(
308+
t,
309+
tc.expectedCallCount,
310+
mockStorer.callCountListMetricsOverTimeWithAggregatedTotals,
311+
"ListMetricsOverTimeWithAggregatedTotals",
312+
mockCacher,
313+
)
309314
})
310315
}
311316
}

backend/pkg/httpserver/list_feature_wpt_metrics_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,13 @@ func TestListFeatureWPTMetrics(t *testing.T) {
300300
eventPublisher: nil,
301301
baseURL: getTestBaseURL(t)}
302302
assertTestServerRequest(t, &myServer, tc.request, tc.expectedResponse)
303-
assertMocksExpectations(t, tc.expectedCallCount, mockStorer.callCountListMetricsForFeatureIDBrowserAndChannel,
304-
"ListMetricsForFeatureIDBrowserAndChannel", mockCacher)
303+
assertMocksExpectations(
304+
t,
305+
tc.expectedCallCount,
306+
mockStorer.callCountListMetricsForFeatureIDBrowserAndChannel,
307+
"ListMetricsForFeatureIDBrowserAndChannel",
308+
mockCacher,
309+
)
305310
})
306311
}
307312
}

backend/pkg/httpserver/update_notification_channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func validateUpdateNotificationChannel(request *backend.UpdateNotificationChanne
4444
continue
4545
}
4646

47-
if cfg, err := request.Config.AsWebhookConfig(); err == nil && cfg.Type == backend.WebhookConfigTypeWebhook {
47+
if cfg, err := request.Config.AsWebhookConfig(); err == nil &&
48+
cfg.Type == backend.WebhookConfigTypeWebhook {
4849
if err := httputils.ValidateSlackWebhookURL(cfg.Url); err != nil {
4950
fieldErrors.addFieldError("config.url", err)
5051
}

0 commit comments

Comments
 (0)