Files
bookhoard/internal/app/app_test.go
T
john-okeefe 4d0d86838a refactor(core): remove scheduler and simplify app lifecycle
- Delete scheduler.go and scheduler_test.go (no longer needed)
- Simplify App struct by removing Handler interface dependency
- Remove StartScheduler/StopScheduler from app lifecycle
- Update main.go to not pass handler to app constructor
- Remove scheduler mock from app tests, simplify test coverage
2026-02-28 12:56:59 -05:00

61 lines
1.5 KiB
Go

package app
import (
"testing"
"time"
"github.com/labstack/echo/v4"
"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)
app.Shutdown()
}
}