Files
phamnazage-jpg 71cbaf5fa6 test(project): achieve ≥70% package coverage across all internal packages
- store/sqlite: 75.4% (repos + db coverage)
- host/sub2api: 80.8% (httptest mock server, pure function tests)
- app: 74.2% (handler error paths, NewActionSet closures)
- pack: 72.4%
- provision: 75.2%
- access: 77.3%
- config: 94.7% (lookup mock tests)

All tests pass: build, vet, race, coverage gates.
2026-05-15 19:26:25 +08:00

78 lines
1.6 KiB
Go

package main
import (
"context"
"errors"
"testing"
"sub2api-cn-relay-manager/internal/app"
)
func TestRunCallsApplicationServerRunnerAfterBootstrap(t *testing.T) {
serverApp := app.NewServer("127.0.0.1:0", nil, nil)
bootstrapCalled := false
runnerCalled := false
err := run(
context.Background(),
func(context.Context) (*app.Server, error) {
bootstrapCalled = true
return serverApp, nil
},
func(_ context.Context, got *app.Server) error {
runnerCalled = true
if got != serverApp {
t.Fatal("run() passed unexpected server instance to runner")
}
return nil
},
)
if err != nil {
t.Fatalf("run() returned error: %v", err)
}
if !bootstrapCalled {
t.Fatal("run() did not call bootstrap")
}
if !runnerCalled {
t.Fatal("run() did not call server runner")
}
}
func TestRunReturnsBootstrapError(t *testing.T) {
wantErr := errors.New("bootstrap failed")
err := run(
context.Background(),
func(context.Context) (*app.Server, error) {
return nil, wantErr
},
func(context.Context, *app.Server) error {
t.Fatal("run() called runner after bootstrap error")
return nil
},
)
if !errors.Is(err, wantErr) {
t.Fatalf("run() error = %v, want %v", err, wantErr)
}
}
func TestRunReturnsApplicationRunError(t *testing.T) {
wantErr := errors.New("server run failed")
serverApp := app.NewServer("127.0.0.1:0", nil, nil)
err := run(
context.Background(),
func(context.Context) (*app.Server, error) {
return serverApp, nil
},
func(context.Context, *app.Server) error {
return wantErr
},
)
if !errors.Is(err, wantErr) {
t.Fatalf("run() error = %v, want %v", err, wantErr)
}
}