detached cda1f8c

test(container): add coverage for getNetworkForApp using live config provider

commit
cda1f8cf3d3c89d2b1fe725a8ae79f3d8a31eb1e
author
brice · · 2026-03-15 16:11 UTC
parent
ef44fd8
signature
unsigned
1 file · +29 -0
M internal/usecase/container/service_test.go +29 -0
@@ -155,6 +155,35 @@ func TestService_ResolveAttachments_GroupBasedViaProvider(t *testing.T) {
155155 assert.Empty(t, result)
156156 }
157157
158+func TestService_GetNetworkForApp_UsesLiveConfigProvider(t *testing.T) {
159+ provider := &fakeConfigProvider{
160+ attachments: map[string][]string{},
161+ networkGroups: map[string][]string{
162+ "shared-group": {"app1.example.com", "app2.example.com"},
163+ },
164+ }
165+
166+ svc := NewService(
167+ mocks.NewMockContainerRuntime(t),
168+ mocks.NewMockEnvLoader(t),
169+ mocks.NewMockEventPublisher(t),
170+ nil, Config{NetworkIsolation: true, NetworkPrefix: "gordon"}, provider,
171+ )
172+
173+ // Should use group network: generateNetworkName produces "gordon-shared-group"
174+ network := svc.getNetworkForApp("app1.example.com")
175+ assert.Equal(t, "gordon-shared-group", network)
176+
177+ // Simulate adding a domain to a group after construction
178+ provider.networkGroups["shared-group"] = append(provider.networkGroups["shared-group"], "app3.example.com")
179+ network = svc.getNetworkForApp("app3.example.com")
180+ assert.Equal(t, "gordon-shared-group", network)
181+
182+ // Domain not in any group gets its own network: "gordon-solo-example-com"
183+ network = svc.getNetworkForApp("solo.example.com")
184+ assert.Equal(t, "gordon-solo-example-com", network)
185+}
186+
158187 func TestService_ManagedContainersMetric_GlobalSeriesOnDeployReplaceAndRemove(t *testing.T) {
159188 runtime := mocks.NewMockContainerRuntime(t)
160189 envLoader := mocks.NewMockEnvLoader(t)
@@ -155,6 +155,35 @@ func TestService_ResolveAttachments_GroupBasedViaProvider(t *testing.T) {
155 assert.Empty(t, result)155 assert.Empty(t, result)
156 }156 }
157 157
158+func TestService_GetNetworkForApp_UsesLiveConfigProvider(t *testing.T) {
159+ provider := &fakeConfigProvider{
160+ attachments: map[string][]string{},
161+ networkGroups: map[string][]string{
162+ "shared-group": {"app1.example.com", "app2.example.com"},
163+ },
164+ }
165+
166+ svc := NewService(
167+ mocks.NewMockContainerRuntime(t),
168+ mocks.NewMockEnvLoader(t),
169+ mocks.NewMockEventPublisher(t),
170+ nil, Config{NetworkIsolation: true, NetworkPrefix: "gordon"}, provider,
171+ )
172+
173+ // Should use group network: generateNetworkName produces "gordon-shared-group"
174+ network := svc.getNetworkForApp("app1.example.com")
175+ assert.Equal(t, "gordon-shared-group", network)
176+
177+ // Simulate adding a domain to a group after construction
178+ provider.networkGroups["shared-group"] = append(provider.networkGroups["shared-group"], "app3.example.com")
179+ network = svc.getNetworkForApp("app3.example.com")
180+ assert.Equal(t, "gordon-shared-group", network)
181+
182+ // Domain not in any group gets its own network: "gordon-solo-example-com"
183+ network = svc.getNetworkForApp("solo.example.com")
184+ assert.Equal(t, "gordon-solo-example-com", network)
185+}
186+
158 func TestService_ManagedContainersMetric_GlobalSeriesOnDeployReplaceAndRemove(t *testing.T) {187 func TestService_ManagedContainersMetric_GlobalSeriesOnDeployReplaceAndRemove(t *testing.T) {
159 runtime := mocks.NewMockContainerRuntime(t)188 runtime := mocks.NewMockContainerRuntime(t)
160 envLoader := mocks.NewMockEnvLoader(t)189 envLoader := mocks.NewMockEnvLoader(t)

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