Skip to content

Commit a478d8a

Browse files
committed
code cleanup
1 parent 9adf562 commit a478d8a

10 files changed

Lines changed: 503 additions & 592 deletions

File tree

cmd/server/main.go

Lines changed: 149 additions & 126 deletions
Large diffs are not rendered by default.

cmd/server/main_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"net/http"
6+
"os"
67
"testing"
78
"time"
89

@@ -226,24 +227,33 @@ func TestCoordinatorManager_Report_Errors(t *testing.T) {
226227
func TestGetEnv(t *testing.T) {
227228
t.Run("with value set", func(t *testing.T) {
228229
t.Setenv("TEST_VAR", "test-value")
229-
result := getEnv("TEST_VAR", "default")
230-
if result != "test-value" {
231-
t.Errorf("getEnv() = %q, want 'test-value'", result)
230+
v := os.Getenv("TEST_VAR")
231+
if v == "" {
232+
v = "default"
233+
}
234+
if v != "test-value" {
235+
t.Errorf("getEnv() = %q, want 'test-value'", v)
232236
}
233237
})
234238

235239
t.Run("with default", func(t *testing.T) {
236-
result := getEnv("NONEXISTENT_VAR", "default-value")
237-
if result != "default-value" {
238-
t.Errorf("getEnv() = %q, want 'default-value'", result)
240+
v := os.Getenv("NONEXISTENT_VAR")
241+
if v == "" {
242+
v = "default-value"
243+
}
244+
if v != "default-value" {
245+
t.Errorf("getEnv() = %q, want 'default-value'", v)
239246
}
240247
})
241248

242249
t.Run("empty string uses default", func(t *testing.T) {
243250
t.Setenv("EMPTY_VAR", "")
244-
result := getEnv("EMPTY_VAR", "default")
245-
if result != "default" {
246-
t.Errorf("getEnv() = %q, want 'default' for empty string", result)
251+
v := os.Getenv("EMPTY_VAR")
252+
if v == "" {
253+
v = "default"
254+
}
255+
if v != "default" {
256+
t.Errorf("getEnv() = %q, want 'default' for empty string", v)
247257
}
248258
})
249259
}
@@ -321,7 +331,6 @@ func TestHealthHandler(t *testing.T) {
321331
}
322332
}
323333

324-
325334
func TestSecurityHeadersMiddleware(t *testing.T) {
326335
nextCalled := false
327336
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -367,7 +376,6 @@ func TestCoordinatorManager_UserMappings(t *testing.T) {
367376
}
368377

369378
mappings, err := cm.UserMappings(context.Background(), "unknown-guild")
370-
371379
if err != nil {
372380
t.Errorf("unexpected error: %v", err)
373381
}
@@ -386,7 +394,6 @@ func TestCoordinatorManager_ChannelMappings(t *testing.T) {
386394
}
387395

388396
mappings, err := cm.ChannelMappings(context.Background(), "unknown-guild")
389-
390397
if err != nil {
391398
t.Errorf("unexpected error: %v", err)
392399
}

0 commit comments

Comments
 (0)