Repository navigation
Expand file tree
/
Copy pathapp_test.go
More file actions
720 lines (563 loc) · 21.9 KB
/
Copy pathapp_test.go
File metadata and controls
720 lines (563 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
package wind
import (
"context"
"errors"
"strings"
"sync/atomic"
"testing"
"time"
)
// waitFor blocks until ch is closed or the deadline elapses, failing the test
// on timeout. This keeps tests deterministic without arbitrary sleeps.
func waitFor(t *testing.T, name string, ch <-chan struct{}) {
t.Helper()
select {
case <-ch:
case <-time.After(3 * time.Second):
t.Fatalf("%s did not happen within 3s", name)
}
}
// ---------------------------------------------------------------------------
// BUG-1 regression: the context passed to Server.Stop during graceful shutdown
// must NOT be already cancelled — otherwise stopTimeout is meaningless.
// ---------------------------------------------------------------------------
func TestApp_Run_GracefulShutdown_StopContextIsValid(t *testing.T) {
srv := newMockServer("srv-1")
app := New(WithServer(srv))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
// Wait for the server to actually start before triggering shutdown.
waitFor(t, "server start", srv.started)
// Trigger graceful shutdown by cancelling the Run context.
cancel()
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
if !srv.stopCalled.Load() {
t.Fatal("expected Stop to be called, but it was not")
}
// The crucial BUG-1 assertion: stopCtx must have been alive at the
// moment Stop was called. We use the snapshot because the caller cancels
// stopCtx via defer right after Stop returns.
if err := srv.stopContextErr(); err != nil {
t.Fatalf("Stop context was already cancelled at call time: %v — stopTimeout window is broken (BUG-1)", err)
}
}
// ---------------------------------------------------------------------------
// BUG-3 regression: when one server crashes, every other server must receive
// a Stop call so the whole app exits cleanly.
// ---------------------------------------------------------------------------
func TestApp_Run_ServerCrash_StopsOtherServers(t *testing.T) {
crashErr := errors.New("boom")
// crashSrv returns startErr immediately, simulating a crash.
crashSrv := newMockServer("crash").withStartErr(crashErr)
// healthySrv blocks until its context is cancelled.
healthySrv := newMockServer("healthy")
app := New(WithServer(crashSrv, healthySrv))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
// The crash error should propagate from Run.
if err := <-errCh; !errors.Is(err, crashErr) {
t.Fatalf("expected crash error %v, got %v", crashErr, err)
}
// The healthy server must have been stopped (BUG-3 fix).
if !healthySrv.stopCalled.Load() {
t.Fatal("healthy server was not stopped after crash — overall graceful exit broken (BUG-3)")
}
}
// ---------------------------------------------------------------------------
// BUG-3 regression (Stop propagation): the stop context delivered to servers
// during a crash-induced shutdown must also be valid (BUG-1 applies here too).
// ---------------------------------------------------------------------------
func TestApp_Run_ServerCrash_StopContextIsValid(t *testing.T) {
crashErr := errors.New("kaboom")
crashSrv := newMockServer("crash").withStartErr(crashErr)
healthySrv := newMockServer("healthy")
app := New(WithServer(crashSrv, healthySrv))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
if err := <-errCh; !errors.Is(err, crashErr) {
t.Fatalf("expected crash error %v, got %v", crashErr, err)
}
waitFor(t, "healthy server stop", healthySrv.stopped)
if err := healthySrv.stopContextErr(); err != nil {
t.Fatalf("Stop context was already cancelled during crash shutdown: %v (BUG-1)", err)
}
}
// ---------------------------------------------------------------------------
// Verify that multiple servers all start and all stop during a normal
// graceful shutdown.
// ---------------------------------------------------------------------------
func TestApp_Run_MultipleServers_AllStartAndStop(t *testing.T) {
s1 := newMockServer("srv-1")
s2 := newMockServer("srv-2")
s3 := newMockServer("srv-3")
app := New(WithServer(s1, s2, s3))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "srv-1 start", s1.started)
waitFor(t, "srv-2 start", s2.started)
waitFor(t, "srv-3 start", s3.started)
cancel()
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
for _, s := range []*mockServer{s1, s2, s3} {
if !s.startCalled.Load() {
t.Errorf("%s was never started", s.name)
}
if !s.stopCalled.Load() {
t.Errorf("%s was never stopped", s.name)
}
}
}
// ---------------------------------------------------------------------------
// ISSUE-1 regression: Stop() called from another goroutine while Run() is
// active must trigger exactly ONE Stop per server — never a double-Stop.
// ---------------------------------------------------------------------------
func TestApp_Stop_NoDoubleStop(t *testing.T) {
s1 := newMockServer("srv-1")
s2 := newMockServer("srv-2")
app := New(WithServer(s1, s2))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
waitFor(t, "srv-1 start", s1.started)
waitFor(t, "srv-2 start", s2.started)
stopCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := app.Stop(stopCtx); err != nil {
t.Fatalf("Stop returned unexpected error: %v", err)
}
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
for _, s := range []*mockServer{s1, s2} {
if count := s.stopCount.Load(); count != 1 {
t.Errorf("%s was stopped %d times, expected exactly 1 (ISSUE-1 double-Stop)", s.name, count)
}
}
}
// ---------------------------------------------------------------------------
// ISSUE-3 regression: when a server's Start returns nil (self-exit), the
// application must still shut down all other servers cleanly.
// ---------------------------------------------------------------------------
func TestApp_Run_ServerSelfExit_StopsOtherServers(t *testing.T) {
// selfExitSrv returns nil from Start immediately, simulating a clean exit.
selfExitSrv := newMockServer("self-exit").withSelfExit()
healthySrv := newMockServer("healthy")
app := New(WithServer(selfExitSrv, healthySrv))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
// Run should return nil — self-exit is not an error.
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
// The healthy server must have been stopped (ISSUE-3 fix).
if !healthySrv.stopCalled.Load() {
t.Fatal("healthy server was not stopped after self-exit — app hung indefinitely (ISSUE-3)")
}
}
// ---------------------------------------------------------------------------
// FINDING-1 regression: calling Run more than once on the same [*App] must
// return [wind.ErrAppAlreadyRunning] instead of silently racing or corrupting
// internal state.
// ---------------------------------------------------------------------------
func TestApp_Run_DoubleRun_ReturnsErrAppAlreadyRunning(t *testing.T) {
srv := newMockServer("srv-1")
app := New(WithServer(srv))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
// Second Run must be rejected immediately.
if err := app.Run(context.Background()); !errors.Is(err, ErrAppAlreadyRunning) {
t.Fatalf("expected ErrAppAlreadyRunning, got %v (FINDING-1)", err)
}
// Clean up: trigger graceful shutdown.
cancel()
if err := <-errCh; err != nil {
t.Fatalf("first Run returned unexpected error: %v", err)
}
}
func TestApp_Stop_GracefulShutdown(t *testing.T) {
s1 := newMockServer("srv-1")
s2 := newMockServer("srv-2")
app := New(WithServer(s1, s2))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
waitFor(t, "srv-1 start", s1.started)
waitFor(t, "srv-2 start", s2.started)
stopCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := app.Stop(stopCtx); err != nil {
t.Fatalf("Stop returned unexpected error: %v", err)
}
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
if !s1.stopCalled.Load() {
t.Error("srv-1 was not stopped")
}
if !s2.stopCalled.Load() {
t.Error("srv-2 was not stopped")
}
}
// ---------------------------------------------------------------------------
// FINDING-3: when no servers are registered, Run must still return when the
// context is cancelled. This supports pure worker applications.
// ---------------------------------------------------------------------------
func TestApp_Run_ZeroServers_StopsOnCancel(t *testing.T) {
app := New()
ctx, cancel := context.WithCancel(context.Background())
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
// Give Run time to enter the blocking signal goroutine.
time.Sleep(50 * time.Millisecond)
cancel()
select {
case err := <-errCh:
if err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
case <-time.After(3 * time.Second):
t.Fatal("Run did not return after ctx cancel (FINDING-3)")
}
}
// ---------------------------------------------------------------------------
// FINDING-4: when a server's Stop returns an error, that error must
// propagate from Run — not be silently swallowed by errgroup's
// context.Canceled.
//
// Note: this test relies on a deterministic scheduling order: the Stop
// watcher goroutine reaches <-egCtx.Done() before the Start goroutine
// (Start must first execute Store + close before blocking on <-ctx.Done()).
// This ordering has been verified stable across 100+ runs at GOMAXPROCS=1.
// The firstStopErr / stopErrOnce mechanism in Run provides an additional
// safety net regardless of scheduling order.
// ---------------------------------------------------------------------------
func TestApp_Run_StopError_Propagates(t *testing.T) {
stopErr := errors.New("stop failed")
srv := newMockServer("srv-1").withStopErr(stopErr)
app := New(WithServer(srv))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
select {
case err := <-errCh:
if !errors.Is(err, stopErr) {
t.Fatalf("expected stop error %v, got %v (FINDING-4)", stopErr, err)
}
case <-time.After(3 * time.Second):
t.Fatal("Run did not return after cancel")
}
}
// ---------------------------------------------------------------------------
// Lifecycle hooks: WithBeforeStop and WithAfterStop must be called in the
// correct order relative to server Start/Stop.
// ---------------------------------------------------------------------------
func TestApp_Run_LifecycleHooks_Order(t *testing.T) {
srv := newMockServer("srv-1")
var beforeCalled atomic.Int32
var afterCalled atomic.Int32
app := New(
WithServer(srv),
WithBeforeStop(func(ctx context.Context) error {
beforeCalled.Store(1)
return nil
}),
WithAfterStop(func(ctx context.Context) error {
// AfterStop should run after server Stop
if !srv.stopCalled.Load() {
t.Error("afterStop ran before server was stopped")
}
afterCalled.Store(1)
return nil
}),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
if beforeCalled.Load() != 1 {
t.Error("beforeStop hook was not called")
}
if afterCalled.Load() != 1 {
t.Error("afterStop hook was not called")
}
}
// ---------------------------------------------------------------------------
// Ordering guarantee: BeforeStop hooks must complete BEFORE any server's
// Stop is called. The old design ran them concurrently inside the same
// errgroup, creating a race (BUG). This test blocks the hook until the test
// signals it to proceed, then asserts that Server.Stop has NOT been called
// while the hook was still blocking.
// ---------------------------------------------------------------------------
func TestApp_Run_BeforeStopRunsBeforeStop(t *testing.T) {
srv := newMockServer("srv-1")
beforeProceed := make(chan struct{})
app := New(
WithServer(srv),
WithBeforeStop(func(ctx context.Context) error {
// Block until the test signals us to proceed.
<-beforeProceed
return nil
}),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
// Give shutdown time to reach the BeforeStop hook. The hook is now
// blocking, so Server.Stop should NOT have been called yet.
time.Sleep(50 * time.Millisecond)
select {
case <-srv.stopped:
t.Fatal("server Stop was called while beforeStop hook was still blocking (ordering BUG)")
default:
// Good: Stop hasn't been called yet because beforeStop is blocking.
}
// Release the hook; Run should now proceed to Phase 3 (Server.Stop).
close(beforeProceed)
if err := <-errCh; err != nil {
t.Fatalf("Run returned unexpected error: %v", err)
}
}
// ---------------------------------------------------------------------------
// App.Err must return the same error that Run returned, after Done is closed.
// ---------------------------------------------------------------------------
func TestApp_Err_ReturnsRunError(t *testing.T) {
crashErr := errors.New("crash")
crashSrv := newMockServer("crash").withStartErr(crashErr)
app := New(WithServer(crashSrv))
runErrCh := make(chan error, 1)
go func() { runErrCh <- app.Run(context.Background()) }()
runErr := <-runErrCh
// Wait for Done to close.
<-app.Done()
// Err should return the same error.
if got := app.Err(); !errors.Is(got, crashErr) {
t.Fatalf("Err() = %v, want %v", got, crashErr)
}
if !errors.Is(runErr, crashErr) {
t.Fatalf("Run returned %v, want %v", runErr, crashErr)
}
}
// ---------------------------------------------------------------------------
// App.Err must return nil before Run has completed.
// ---------------------------------------------------------------------------
func TestApp_Err_NilBeforeRunCompletes(t *testing.T) {
app := New()
if err := app.Err(); err != nil {
t.Fatalf("Err() before Run should return nil, got %v", err)
}
}
// ---------------------------------------------------------------------------
// Panic recovery: a panicking Server.Start must be recovered by App.Run,
// converted to an error, and must still trigger Stop for other servers.
// Without recover, the entire process would crash.
// ---------------------------------------------------------------------------
func TestApp_Run_ServerStartPanic_RecoversAndStopsOthers(t *testing.T) {
panicSrv := newMockServer("panicky").withStartPanic()
healthySrv := newMockServer("healthy")
app := New(WithServer(panicSrv, healthySrv))
errCh := make(chan error, 1)
go func() { errCh <- app.Run(context.Background()) }()
err := <-errCh
if err == nil {
t.Fatal("expected non-nil error from Start panic, got nil")
}
if !strings.Contains(err.Error(), "panicked") {
t.Fatalf("expected panic-converted error, got: %v", err)
}
// The healthy server must have been stopped despite the other's panic.
if !healthySrv.stopCalled.Load() {
t.Fatal("healthy server was not stopped after Start panic — graceful exit broken")
}
}
// ---------------------------------------------------------------------------
// Panic recovery: a panicking Server.Stop must not crash the process or skip
// other servers' Stop calls.
// ---------------------------------------------------------------------------
func TestApp_Run_ServerStopPanic_OthersStillStopped(t *testing.T) {
panicSrv := newMockServer("panicky").withStopPanic()
healthySrv := newMockServer("healthy")
app := New(WithServer(panicSrv, healthySrv))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "panicky server start", panicSrv.started)
waitFor(t, "healthy server start", healthySrv.started)
cancel()
// Run should return an error (the panic-converted Stop error).
err := <-errCh
if err == nil {
t.Fatal("expected non-nil error from Stop panic, got nil")
}
if !strings.Contains(err.Error(), "panicked") {
t.Fatalf("expected panic-converted error, got: %v", err)
}
// The healthy server must still have been stopped.
if !healthySrv.stopCalled.Load() {
t.Fatal("healthy server was not stopped after another server's Stop panic")
}
}
// ---------------------------------------------------------------------------
// Panic recovery: a panicking BeforeStop hook must not skip subsequent hooks
// or the Server.Stop phase.
// ---------------------------------------------------------------------------
func TestApp_Run_BeforeStopPanic_ContinuesShutdown(t *testing.T) {
srv := newMockServer("srv-1")
hook2Called := atomic.Bool{}
app := New(
WithServer(srv),
WithBeforeStop(func(ctx context.Context) error {
panic("hook boom")
}),
WithBeforeStop(func(ctx context.Context) error {
hook2Called.Store(true)
return nil
}),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
// Hook panics are recovered and logged but, like normal hook errors, do
// not propagate to Run's return value (log-and-continue policy).
err := <-errCh
if err != nil {
t.Fatalf("Run should return nil for a normal shutdown even with a hook panic, got: %v", err)
}
// The second hook must still have been called.
if !hook2Called.Load() {
t.Fatal("second beforeStop hook was skipped after first hook panicked")
}
// The server must still have been stopped.
if !srv.stopCalled.Load() {
t.Fatal("server was not stopped after beforeStop hook panic")
}
}
// ---------------------------------------------------------------------------
// Panic recovery: a panicking AfterStop hook must not crash the process.
// Run should return the panic-converted error.
// ---------------------------------------------------------------------------
func TestApp_Run_AfterStopPanic_RecoversGracefully(t *testing.T) {
srv := newMockServer("srv-1")
app := New(
WithServer(srv),
WithAfterStop(func(ctx context.Context) error {
panic("after boom")
}),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
// AfterStop panic is recovered and logged but does not change Run's
// return value (log-and-continue policy, same as normal hook errors).
err := <-errCh
if err != nil {
t.Fatalf("Run should return nil for a normal shutdown even with AfterStop panic, got: %v", err)
}
}
// ---------------------------------------------------------------------------
// WithInstanceID / InstanceID accessor: custom instance ID is returned as-is.
// ---------------------------------------------------------------------------
func TestApp_InstanceID_Custom(t *testing.T) {
app := New(
WithID("svc-1"),
WithVersion("1.0.0"),
WithInstanceID("my-custom-instance-id"),
)
if got := app.InstanceID(); got != "my-custom-instance-id" {
t.Fatalf("expected custom instance ID, got %q", got)
}
}
// ---------------------------------------------------------------------------
// InstanceID auto-generation: when not explicitly set, a non-empty ID is
// generated containing appId and version.
// ---------------------------------------------------------------------------
func TestApp_InstanceID_AutoGenerated(t *testing.T) {
app := New(
WithID("svc-1"),
WithVersion("1.0.0"),
)
id := app.InstanceID()
if id == "" {
t.Fatal("auto-generated instance ID should not be empty")
}
if !strings.Contains(id, "svc-1") {
t.Fatalf("auto-generated ID should contain appId, got %q", id)
}
if !strings.Contains(id, "1.0.0") {
t.Fatalf("auto-generated ID should contain version, got %q", id)
}
if !strings.Contains(id, "@") {
t.Fatalf("auto-generated ID should contain hostname separator @, got %q", id)
}
// Calling InstanceID() again must return the same value (cached).
if got := app.InstanceID(); got != id {
t.Fatalf("InstanceID() not stable: first %q then %q", id, got)
}
}
// ---------------------------------------------------------------------------
// Banner: when enabled, Run does not crash and completes normally.
// ---------------------------------------------------------------------------
func TestApp_Run_BannerEnabled_CompletesNormally(t *testing.T) {
srv := newMockServer("srv-1")
app := New(
WithID("svc-1"),
WithName("test-service"),
WithVersion("1.0.0"),
WithBanner(true),
WithServer(srv),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
errCh := make(chan error, 1)
go func() { errCh <- app.Run(ctx) }()
waitFor(t, "server start", srv.started)
cancel()
if err := <-errCh; err != nil {
t.Fatalf("Run with banner returned unexpected error: %v", err)
}
}
// ---------------------------------------------------------------------------
// Banner: when disabled (default), no banner is printed. We verify this
// indirectly by confirming that InstanceID is NOT generated when banner is off
// and InstanceID() is never called.
// ---------------------------------------------------------------------------
func TestApp_Banner_DefaultDisabled(t *testing.T) {
app := New(
WithID("svc-1"),
WithVersion("1.0.0"),
)
// banner should be false by default.
if app.opts.banner {
t.Fatal("banner should be disabled by default")
}
// instanceID should be empty until explicitly requested.
if app.opts.instanceID != "" {
t.Fatal("instanceID should be empty when not requested")
}
}