Peter Sanchez: 1 Run modernizer on codebase. 4 files changed, 30 insertions(+), 30 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/195/mbox | git am -3Learn more about email & git
--- api/api_test.go | 26 +++++++++++++------------- domain/integration_test.go | 30 +++++++++++++++--------------- slack/commands.go | 2 +- slack/routes.go | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index 0dabe06..465c019 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -219,7 +219,7 @@ func TestDirective(t *testing.T) { User: user3, } - type GraphQLResponse struct{ + type GraphQLResponse struct { Org models.Organization `json:"addOrganization"` } var result GraphQLResponse @@ -2813,7 +2813,7 @@ func TestAPI(t *testing.T) { return err } - for i := 0; i < 2; i++ { + for i := range 2 { baseURL := models.BaseURL{ URL: fmt.Sprintf("https://hidden.com/%d", i), Visibility: models.VisibilityPublic, @@ -2821,7 +2821,7 @@ func TestAPI(t *testing.T) { if err := baseURL.Store(dbCtx); err != nil { return fmt.Errorf("failed to store hidden base URL %d: %w", i, err) } - + link := models.OrgLink{ Title: fmt.Sprintf("Hidden Link %d", i), URL: fmt.Sprintf("https://hidden.com/%d", i), @@ -2836,7 +2836,7 @@ func TestAPI(t *testing.T) { } // Add 5 links to forced hidden org - it should still stay hidden - for i := 0; i < 5; i++ { + for i := range 5 { baseURL := models.BaseURL{ URL: fmt.Sprintf("https://forced.com/%d", i), Visibility: models.VisibilityPublic, @@ -2844,7 +2844,7 @@ func TestAPI(t *testing.T) { if err := baseURL.Store(dbCtx); err != nil { return fmt.Errorf("failed to store forced base URL %d: %w", i, err) } - + link := models.OrgLink{ Title: fmt.Sprintf("Forced Link %d", i), URL: fmt.Sprintf("https://forced.com/%d", i), @@ -2858,7 +2858,7 @@ func TestAPI(t *testing.T) { } } - for i := 0; i < 5; i++ { + for i := range 5 { baseURL := models.BaseURL{ URL: fmt.Sprintf("https://public.com/%d", i), Visibility: models.VisibilityPublic, @@ -2866,7 +2866,7 @@ func TestAPI(t *testing.T) { if err := baseURL.Store(dbCtx); err != nil { return fmt.Errorf("failed to store public base URL %d: %w", i, err) } - + link := models.OrgLink{ Title: fmt.Sprintf("Public Link %d", i), URL: fmt.Sprintf("https://public.com/%d", i), @@ -2887,7 +2887,7 @@ func TestAPI(t *testing.T) { if err := baseURL.Store(dbCtx); err != nil { return fmt.Errorf("failed to store personal base URL: %w", err) } - + link := models.OrgLink{ Title: "Personal Link", URL: "https://personal.com", @@ -2977,11 +2977,11 @@ func TestAPI(t *testing.T) { op.Var("orgSlug", "personal-org") err := links.Execute(ctx, op, &result) c.NoError(err) - + // Should return all tags for personal-org // At minimum we have 5 from test data, but previous tests may create more c.GreaterOrEqual(len(result.GetTags.Result), 5) - + // Verify expected test data tags are present tagNames := make(map[string]bool) for _, tag := range result.GetTags.Result { @@ -3018,7 +3018,7 @@ func TestAPI(t *testing.T) { linksOp.Var("service", "LINKS") err := links.Execute(ctx, linksOp, &linksResult) c.NoError(err) - + // Should return at least 3 tags for LINKS service (may have more from previous tests) c.GreaterOrEqual(len(linksResult.GetTags.Result), 3) linksTags := make(map[string]bool) @@ -3045,7 +3045,7 @@ func TestAPI(t *testing.T) { shortOp.Var("service", "SHORT") err = links.Execute(ctx, shortOp, &shortResult) c.NoError(err) - + // Should return at least 3 tags for SHORT service (may have more from previous tests) c.GreaterOrEqual(len(shortResult.GetTags.Result), 3) shortTags := make(map[string]bool) @@ -3072,7 +3072,7 @@ func TestAPI(t *testing.T) { listOp.Var("service", "LIST") err = links.Execute(ctx, listOp, &listResult) c.NoError(err) - + // Should return at least 2 tags for LIST service (may have more from previous tests) c.GreaterOrEqual(len(listResult.GetTags.Result), 2) listTags := make(map[string]bool) diff --git a/domain/integration_test.go b/domain/integration_test.go index 6f671d7..a05bb1e 100644 --- a/domain/integration_test.go +++ b/domain/integration_test.go @@ -56,7 +56,7 @@ func TestDomainValidationContextCancellation(t *testing.T) { // Set up basic test data - create a test domain // First try to delete any existing test domain db.Exec("DELETE FROM domains WHERE lookup_name = 'test.example.com'") - + _, err := db.Exec(` INSERT INTO domains (lookup_name, name, service, status, level, is_active) VALUES ($1, $2, $3, $4, $5, $6) @@ -78,7 +78,7 @@ func TestDomainValidationContextCancellation(t *testing.T) { cfg := &config.Config{Debug: true} server.New(e, db, cfg).Initialize() - // Add middleware in same order as production + // Add middleware in same order as production e.Use( // Custom context middleware (matches server.DefaultMiddlewareWithConfig) func(next echo.HandlerFunc) echo.HandlerFunc { @@ -87,15 +87,15 @@ func TestDomainValidationContextCancellation(t *testing.T) { return next(ctx) } }, - database.DBIMiddleware(db), // DBI must be first - func(next echo.HandlerFunc) echo.HandlerFunc { // Add timezone context + database.DBIMiddleware(db), // DBI must be first + func(next echo.HandlerFunc) echo.HandlerFunc { // Add timezone context return func(c echo.Context) error { ctx := timezone.Context(c.Request().Context(), "UTC") c.SetRequest(c.Request().WithContext(ctx)) return next(c) } }, - DomainContext(models.DomainServiceLinks), // Domain validation + DomainContext(models.DomainServiceLinks), // Domain validation ) // Simple handler that should never be reached due to domain validation failure @@ -106,7 +106,7 @@ func TestDomainValidationContextCancellation(t *testing.T) { // Test 1: Context cancellation during domain validation req := httptest.NewRequest(http.MethodGet, "/test", nil) req.Host = "test.example.com" // Valid domain that exists in DB - + // Create cancellable context ctx, cancel := context.WithCancel(req.Context()) req = req.WithContext(ctx) @@ -137,18 +137,18 @@ func TestDomainValidationContextCancellation(t *testing.T) { // Verify no connection leak occurred - this is the critical test statsAfter := db.Stats() if statsAfter.OpenConnections > statsBefore.OpenConnections { - t.Errorf("Connection leak detected after context cancellation: before=%d, after=%d", + t.Errorf("Connection leak detected after context cancellation: before=%d, after=%d", statsBefore.OpenConnections, statsAfter.OpenConnections) } - t.Logf("Context cancellation test - Connection stats before: %d, after: %d", + t.Logf("Context cancellation test - Connection stats before: %d, after: %d", statsBefore.OpenConnections, statsAfter.OpenConnections) // Test 2: Multiple rapid cancellations (stress test) - for i := 0; i < 5; i++ { + for range 5 { req := httptest.NewRequest(http.MethodGet, "/test", nil) req.Host = "test.example.com" - + ctx, cancel := context.WithCancel(req.Context()) req = req.WithContext(ctx) rec := httptest.NewRecorder() @@ -165,13 +165,13 @@ func TestDomainValidationContextCancellation(t *testing.T) { // Final connection check after stress test time.Sleep(500 * time.Millisecond) statsFinal := db.Stats() - + if statsFinal.OpenConnections > statsBefore.OpenConnections+2 { // Allow some tolerance - t.Errorf("Connection leak detected after stress test: before=%d, final=%d", + t.Errorf("Connection leak detected after stress test: before=%d, final=%d", statsBefore.OpenConnections, statsFinal.OpenConnections) } - t.Logf("Stress test complete - Connection stats before: %d, final: %d", + t.Logf("Stress test complete - Connection stats before: %d, final: %d", statsBefore.OpenConnections, statsFinal.OpenConnections) } @@ -189,7 +189,7 @@ func TestValidDomainWithContextCancellation(t *testing.T) { // Call ValidDomain with cancelled context _, err := ValidDomain(ctx, "test.example.com", models.DomainServiceLinks, false) - + // Should get context cancelled error if err == nil { t.Error("Expected error due to context cancellation") @@ -197,4 +197,4 @@ func TestValidDomainWithContextCancellation(t *testing.T) { // The key is that this doesn't leak connections // The WithTx fix should handle the rollback automatically -} \ No newline at end of file +} diff --git a/slack/commands.go b/slack/commands.go index e7282a9..3dea6fc 100644 --- a/slack/commands.go +++ b/slack/commands.go @@ -404,7 +404,7 @@ func sendInstructionLink(c echo.Context, slackConn *models.SlackConnection, url, block := SlackBlock{} apiURL := "https://slack.com/api/chat.postMessage" msg := lt.Translate("Please link your slack user with link: %s", url) - requestBody := []byte(fmt.Sprintf(`{"channel": "%s", "text": "%s"}`, slackUser, msg)) + requestBody := fmt.Appendf(nil, `{"channel": "%s", "text": "%s"}`, slackUser, msg) req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(requestBody)) if err != nil { return nil, err diff --git a/slack/routes.go b/slack/routes.go index 879f132..49bc4d3 100644 --- a/slack/routes.go +++ b/slack/routes.go @@ -181,7 +181,7 @@ func (s *Service) SlashCommand(c echo.Context) error { } timestamp := req.Header.Get("X-Slack-Request-Timestamp") hasher := hmac.New(sha256.New, []byte(secret)) - hasher.Write([]byte(fmt.Sprintf("%s:%s:%s", version, timestamp, string(body)))) + hasher.Write(fmt.Appendf(nil, "%s:%s:%s", version, timestamp, string(body))) hashString := fmt.Sprintf("%s=%s", version, hex.EncodeToString(hasher.Sum(nil))) if hashString != req.Header.Get("X-Slack-Signature") { return fmt.Errorf("Invalid signature") -- 2.49.1
Applied. To git@git.code.netlandish.com:~netlandish/links 73a8206..da7790f master -> master