Files
bookhoard/internal/app/app_test.go
T
john-okeefe 0842ae6efa refactor: remove unnecessary type conversions and handle ignored errors across codebase
Remove redundant type conversions that Go 1.26 makes unnecessary or that
were already no-ops:

- uuid.UUID(x.Bytes) → x.Bytes (uuid.UUID is [16]byte, same as pgtype UUID Bytes)
- pgtype.UUID{Bytes: [16]byte(u), Valid: true} → pgtype.UUID{Bytes: u, Valid: true}
- (*time.Time)(&x.Time) → &x.Time
- json.RawMessage(x) → x where x is already []byte
- []byte(stringVal) → stringVal where []byte is expected
- int()/int64()/byte() casts on values already of the target type
- Decompressor(fn) → fn (type is identical)

Handle previously ignored error returns:

- collections.go: check json.Unmarshal error in GetCollection
- conversion_service.go: check fileSize.Scan() error
- app_test.go: check app.Shutdown() error in benchmark
2026-04-21 21:15:59 -04:00

64 lines
1.5 KiB
Go

package app
import (
"testing"
"time"
"github.com/labstack/echo/v5"
"github.com/stretchr/testify/assert"
)
// TestApp_New tests App constructor
func TestApp_New(t *testing.T) {
e := echo.New()
app := New(e)
assert.NotNil(t, app, "App should not be nil")
assert.Equal(t, e, app.echo, "Echo instance should be stored")
assert.Equal(t, 30*time.Second, app.shutdownTimeout, "Default shutdown timeout should be 30 seconds")
assert.NotNil(t, app.shutdownDone, "Shutdown done channel should be initialized")
}
// TestApp_SetShutdownTimeout tests configurable shutdown timeout
func TestApp_SetShutdownTimeout(t *testing.T) {
e := echo.New()
app := New(e)
customTimeout := 15 * time.Second
app.SetShutdownTimeout(customTimeout)
assert.Equal(t, customTimeout, app.shutdownTimeout, "Shutdown timeout should be updated")
}
// TestApp_ShutdownDone tests shutdown done channel
func TestApp_ShutdownDone(t *testing.T) {
e := echo.New()
app := New(e)
channel := app.ShutdownDone()
assert.NotNil(t, channel, "ShutdownDone should return a channel")
// Verify it's the same channel by checking if it's readable
select {
case <-channel:
// Channel should not be closed yet
t.Error("ShutdownDone channel should not be closed immediately")
default:
// Expected - channel is open but not ready
}
}
// BenchmarkApp_Shutdown benchmarks the shutdown process
func BenchmarkApp_Shutdown(b *testing.B) {
e := echo.New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
app := New(e)
err := app.Shutdown()
if err != nil {
return
}
}
}