detached b89ced4

refactor: extract testMinDelayConfig helper in container service tests

commit
b89ced45e6017f63bcac64bfbdfd9e206de21cdc
author
brice · · 2026-03-04 09:02 UTC
parent
8582c13
signature
unsigned
1 file · +20 -50
M internal/usecase/container/service_test.go +20 -50
@@ -25,6 +25,16 @@ func testContext() context.Context {
2525 return zerowrap.WithCtx(context.Background(), zerowrap.Default())
2626 }
2727
28+// testMinDelayConfig returns a Config with all timing delays set to 1ms,
29+// suitable for unit tests that don't want to wait for real timeouts.
30+func testMinDelayConfig() Config {
31+ return Config{
32+ ReadinessDelay: time.Millisecond,
33+ DrainDelay: time.Millisecond,
34+ StabilizationDelay: time.Millisecond,
35+ }
36+}
37+
2838 func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) {
2939 t.Helper()
3040
@@ -493,11 +503,7 @@ func TestService_Deploy_ResolvesExistingFromRuntime_WhenMemoryStale(t *testing.T
493503 eventBus := mocks.NewMockEventPublisher(t)
494504 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
495505
496- config := Config{
497- ReadinessDelay: time.Millisecond,
498- DrainDelay: time.Millisecond,
499- StabilizationDelay: time.Millisecond,
500- }
506+ config := testMinDelayConfig()
501507 svc := NewService(runtime, envLoader, eventBus, nil, config)
502508 svc.SetProxyCacheInvalidator(cacheInvalidator)
503509 ctx := testContext()
@@ -593,11 +599,7 @@ func TestService_Deploy_SkipRedundantDeploy_GetImageIDError(t *testing.T) {
593599 envLoader := mocks.NewMockEnvLoader(t)
594600 eventBus := mocks.NewMockEventPublisher(t)
595601
596- config := Config{
597- ReadinessDelay: time.Millisecond,
598- DrainDelay: time.Millisecond,
599- StabilizationDelay: time.Millisecond,
600- }
602+ config := testMinDelayConfig()
601603 svc := NewService(runtime, envLoader, eventBus, nil, config)
602604 ctx := testContext()
603605
@@ -1839,11 +1841,7 @@ func TestService_Deploy_OrphanCleanupRemovesStaleNewContainer(t *testing.T) {
18391841 eventBus := mocks.NewMockEventPublisher(t)
18401842 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
18411843
1842- config := Config{
1843- ReadinessDelay: time.Millisecond,
1844- DrainDelay: time.Millisecond,
1845- StabilizationDelay: time.Millisecond,
1846- }
1844+ config := testMinDelayConfig()
18471845 svc := NewService(runtime, envLoader, eventBus, nil, config)
18481846 svc.SetProxyCacheInvalidator(cacheInvalidator)
18491847 ctx := testContext()
@@ -1913,11 +1911,7 @@ func TestService_Deploy_TrackedTempContainerUsesAlternateTempName(t *testing.T)
19131911 eventBus := mocks.NewMockEventPublisher(t)
19141912 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
19151913
1916- config := Config{
1917- ReadinessDelay: time.Millisecond,
1918- DrainDelay: time.Millisecond,
1919- StabilizationDelay: time.Millisecond,
1920- }
1914+ config := testMinDelayConfig()
19211915 svc := NewService(runtime, envLoader, eventBus, nil, config)
19221916 svc.SetProxyCacheInvalidator(cacheInvalidator)
19231917 ctx := testContext()
@@ -2104,11 +2098,7 @@ func TestService_Deploy_ConcurrentSameDomain(t *testing.T) {
21042098 eventBus := mocks.NewMockEventPublisher(t)
21052099 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
21062100
2107- config := Config{
2108- ReadinessDelay: time.Millisecond,
2109- DrainDelay: time.Millisecond,
2110- StabilizationDelay: time.Millisecond,
2111- }
2101+ config := testMinDelayConfig()
21122102 svc := NewService(runtime, envLoader, eventBus, nil, config)
21132103 svc.SetProxyCacheInvalidator(cacheInvalidator)
21142104 ctx := testContext()
@@ -2244,11 +2234,7 @@ func TestService_Deploy_CacheInvalidationBeforeOldContainerStop(t *testing.T) {
22442234 eventBus := mocks.NewMockEventPublisher(t)
22452235 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
22462236
2247- config := Config{
2248- ReadinessDelay: time.Millisecond,
2249- DrainDelay: time.Millisecond,
2250- StabilizationDelay: time.Millisecond,
2251- }
2237+ config := testMinDelayConfig()
22522238 svc := NewService(runtime, envLoader, eventBus, nil, config)
22532239 svc.SetProxyCacheInvalidator(cacheInvalidator)
22542240 ctx := testContext()
@@ -2325,11 +2311,7 @@ func TestService_Deploy_NilCacheInvalidator(t *testing.T) {
23252311 envLoader := mocks.NewMockEnvLoader(t)
23262312 eventBus := mocks.NewMockEventPublisher(t)
23272313
2328- config := Config{
2329- ReadinessDelay: time.Millisecond,
2330- DrainDelay: time.Millisecond,
2331- StabilizationDelay: time.Millisecond,
2332- }
2314+ config := testMinDelayConfig()
23332315 // Intentionally NOT setting cache invalidator
23342316 svc := NewService(runtime, envLoader, eventBus, nil, config)
23352317 ctx := testContext()
@@ -2484,11 +2466,7 @@ func TestService_Deploy_DoesNotSkipWhenImageIDDiffers(t *testing.T) {
24842466 eventBus := mocks.NewMockEventPublisher(t)
24852467 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
24862468
2487- config := Config{
2488- ReadinessDelay: time.Millisecond,
2489- DrainDelay: time.Millisecond,
2490- StabilizationDelay: time.Millisecond,
2491- }
2469+ config := testMinDelayConfig()
24922470 svc := NewService(runtime, envLoader, eventBus, nil, config)
24932471 svc.SetProxyCacheInvalidator(cacheInvalidator)
24942472 ctx := testContext()
@@ -2587,11 +2565,7 @@ func TestService_Deploy_SkipRedundantDeploy_ContainerNotRunning(t *testing.T) {
25872565 envLoader := mocks.NewMockEnvLoader(t)
25882566 eventBus := mocks.NewMockEventPublisher(t)
25892567
2590- config := Config{
2591- ReadinessDelay: time.Millisecond,
2592- DrainDelay: time.Millisecond,
2593- StabilizationDelay: time.Millisecond,
2594- }
2568+ config := testMinDelayConfig()
25952569 svc := NewService(runtime, envLoader, eventBus, nil, config)
25962570 ctx := testContext()
25972571
@@ -2654,11 +2628,7 @@ func TestService_Deploy_OrphanCleanup_NeverKillsRunningCanonical(t *testing.T) {
26542628 envLoader := mocks.NewMockEnvLoader(t)
26552629 eventBus := mocks.NewMockEventPublisher(t)
26562630
2657- config := Config{
2658- ReadinessDelay: time.Millisecond,
2659- DrainDelay: time.Millisecond,
2660- StabilizationDelay: time.Millisecond,
2661- }
2631+ config := testMinDelayConfig()
26622632 svc := NewService(runtime, envLoader, eventBus, nil, config)
26632633 ctx := testContext()
26642634
@@ -25,6 +25,16 @@ func testContext() context.Context {
25 return zerowrap.WithCtx(context.Background(), zerowrap.Default())25 return zerowrap.WithCtx(context.Background(), zerowrap.Default())
26 }26 }
27 27
28+// testMinDelayConfig returns a Config with all timing delays set to 1ms,
29+// suitable for unit tests that don't want to wait for real timeouts.
30+func testMinDelayConfig() Config {
31+ return Config{
32+ ReadinessDelay: time.Millisecond,
33+ DrainDelay: time.Millisecond,
34+ StabilizationDelay: time.Millisecond,
35+ }
36+}
37+
28 func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) {38 func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) {
29 t.Helper()39 t.Helper()
30 40
@@ -493,11 +503,7 @@ func TestService_Deploy_ResolvesExistingFromRuntime_WhenMemoryStale(t *testing.T
493 eventBus := mocks.NewMockEventPublisher(t)503 eventBus := mocks.NewMockEventPublisher(t)
494 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)504 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
495 505
496- config := Config{506+ config := testMinDelayConfig()
497- ReadinessDelay: time.Millisecond,
498- DrainDelay: time.Millisecond,
499- StabilizationDelay: time.Millisecond,
500- }
501 svc := NewService(runtime, envLoader, eventBus, nil, config)507 svc := NewService(runtime, envLoader, eventBus, nil, config)
502 svc.SetProxyCacheInvalidator(cacheInvalidator)508 svc.SetProxyCacheInvalidator(cacheInvalidator)
503 ctx := testContext()509 ctx := testContext()
@@ -593,11 +599,7 @@ func TestService_Deploy_SkipRedundantDeploy_GetImageIDError(t *testing.T) {
593 envLoader := mocks.NewMockEnvLoader(t)599 envLoader := mocks.NewMockEnvLoader(t)
594 eventBus := mocks.NewMockEventPublisher(t)600 eventBus := mocks.NewMockEventPublisher(t)
595 601
596- config := Config{602+ config := testMinDelayConfig()
597- ReadinessDelay: time.Millisecond,
598- DrainDelay: time.Millisecond,
599- StabilizationDelay: time.Millisecond,
600- }
601 svc := NewService(runtime, envLoader, eventBus, nil, config)603 svc := NewService(runtime, envLoader, eventBus, nil, config)
602 ctx := testContext()604 ctx := testContext()
603 605
@@ -1839,11 +1841,7 @@ func TestService_Deploy_OrphanCleanupRemovesStaleNewContainer(t *testing.T) {
1839 eventBus := mocks.NewMockEventPublisher(t)1841 eventBus := mocks.NewMockEventPublisher(t)
1840 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)1842 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
1841 1843
1842- config := Config{1844+ config := testMinDelayConfig()
1843- ReadinessDelay: time.Millisecond,
1844- DrainDelay: time.Millisecond,
1845- StabilizationDelay: time.Millisecond,
1846- }
1847 svc := NewService(runtime, envLoader, eventBus, nil, config)1845 svc := NewService(runtime, envLoader, eventBus, nil, config)
1848 svc.SetProxyCacheInvalidator(cacheInvalidator)1846 svc.SetProxyCacheInvalidator(cacheInvalidator)
1849 ctx := testContext()1847 ctx := testContext()
@@ -1913,11 +1911,7 @@ func TestService_Deploy_TrackedTempContainerUsesAlternateTempName(t *testing.T)
1913 eventBus := mocks.NewMockEventPublisher(t)1911 eventBus := mocks.NewMockEventPublisher(t)
1914 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)1912 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
1915 1913
1916- config := Config{1914+ config := testMinDelayConfig()
1917- ReadinessDelay: time.Millisecond,
1918- DrainDelay: time.Millisecond,
1919- StabilizationDelay: time.Millisecond,
1920- }
1921 svc := NewService(runtime, envLoader, eventBus, nil, config)1915 svc := NewService(runtime, envLoader, eventBus, nil, config)
1922 svc.SetProxyCacheInvalidator(cacheInvalidator)1916 svc.SetProxyCacheInvalidator(cacheInvalidator)
1923 ctx := testContext()1917 ctx := testContext()
@@ -2104,11 +2098,7 @@ func TestService_Deploy_ConcurrentSameDomain(t *testing.T) {
2104 eventBus := mocks.NewMockEventPublisher(t)2098 eventBus := mocks.NewMockEventPublisher(t)
2105 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)2099 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
2106 2100
2107- config := Config{2101+ config := testMinDelayConfig()
2108- ReadinessDelay: time.Millisecond,
2109- DrainDelay: time.Millisecond,
2110- StabilizationDelay: time.Millisecond,
2111- }
2112 svc := NewService(runtime, envLoader, eventBus, nil, config)2102 svc := NewService(runtime, envLoader, eventBus, nil, config)
2113 svc.SetProxyCacheInvalidator(cacheInvalidator)2103 svc.SetProxyCacheInvalidator(cacheInvalidator)
2114 ctx := testContext()2104 ctx := testContext()
@@ -2244,11 +2234,7 @@ func TestService_Deploy_CacheInvalidationBeforeOldContainerStop(t *testing.T) {
2244 eventBus := mocks.NewMockEventPublisher(t)2234 eventBus := mocks.NewMockEventPublisher(t)
2245 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)2235 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
2246 2236
2247- config := Config{2237+ config := testMinDelayConfig()
2248- ReadinessDelay: time.Millisecond,
2249- DrainDelay: time.Millisecond,
2250- StabilizationDelay: time.Millisecond,
2251- }
2252 svc := NewService(runtime, envLoader, eventBus, nil, config)2238 svc := NewService(runtime, envLoader, eventBus, nil, config)
2253 svc.SetProxyCacheInvalidator(cacheInvalidator)2239 svc.SetProxyCacheInvalidator(cacheInvalidator)
2254 ctx := testContext()2240 ctx := testContext()
@@ -2325,11 +2311,7 @@ func TestService_Deploy_NilCacheInvalidator(t *testing.T) {
2325 envLoader := mocks.NewMockEnvLoader(t)2311 envLoader := mocks.NewMockEnvLoader(t)
2326 eventBus := mocks.NewMockEventPublisher(t)2312 eventBus := mocks.NewMockEventPublisher(t)
2327 2313
2328- config := Config{2314+ config := testMinDelayConfig()
2329- ReadinessDelay: time.Millisecond,
2330- DrainDelay: time.Millisecond,
2331- StabilizationDelay: time.Millisecond,
2332- }
2333 // Intentionally NOT setting cache invalidator2315 // Intentionally NOT setting cache invalidator
2334 svc := NewService(runtime, envLoader, eventBus, nil, config)2316 svc := NewService(runtime, envLoader, eventBus, nil, config)
2335 ctx := testContext()2317 ctx := testContext()
@@ -2484,11 +2466,7 @@ func TestService_Deploy_DoesNotSkipWhenImageIDDiffers(t *testing.T) {
2484 eventBus := mocks.NewMockEventPublisher(t)2466 eventBus := mocks.NewMockEventPublisher(t)
2485 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)2467 cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t)
2486 2468
2487- config := Config{2469+ config := testMinDelayConfig()
2488- ReadinessDelay: time.Millisecond,
2489- DrainDelay: time.Millisecond,
2490- StabilizationDelay: time.Millisecond,
2491- }
2492 svc := NewService(runtime, envLoader, eventBus, nil, config)2470 svc := NewService(runtime, envLoader, eventBus, nil, config)
2493 svc.SetProxyCacheInvalidator(cacheInvalidator)2471 svc.SetProxyCacheInvalidator(cacheInvalidator)
2494 ctx := testContext()2472 ctx := testContext()
@@ -2587,11 +2565,7 @@ func TestService_Deploy_SkipRedundantDeploy_ContainerNotRunning(t *testing.T) {
2587 envLoader := mocks.NewMockEnvLoader(t)2565 envLoader := mocks.NewMockEnvLoader(t)
2588 eventBus := mocks.NewMockEventPublisher(t)2566 eventBus := mocks.NewMockEventPublisher(t)
2589 2567
2590- config := Config{2568+ config := testMinDelayConfig()
2591- ReadinessDelay: time.Millisecond,
2592- DrainDelay: time.Millisecond,
2593- StabilizationDelay: time.Millisecond,
2594- }
2595 svc := NewService(runtime, envLoader, eventBus, nil, config)2569 svc := NewService(runtime, envLoader, eventBus, nil, config)
2596 ctx := testContext()2570 ctx := testContext()
2597 2571
@@ -2654,11 +2628,7 @@ func TestService_Deploy_OrphanCleanup_NeverKillsRunningCanonical(t *testing.T) {
2654 envLoader := mocks.NewMockEnvLoader(t)2628 envLoader := mocks.NewMockEnvLoader(t)
2655 eventBus := mocks.NewMockEventPublisher(t)2629 eventBus := mocks.NewMockEventPublisher(t)
2656 2630
2657- config := Config{2631+ config := testMinDelayConfig()
2658- ReadinessDelay: time.Millisecond,
2659- DrainDelay: time.Millisecond,
2660- StabilizationDelay: time.Millisecond,
2661- }
2662 svc := NewService(runtime, envLoader, eventBus, nil, config)2632 svc := NewService(runtime, envLoader, eventBus, nil, config)
2663 ctx := testContext()2633 ctx := testContext()
2664 2634

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close