-
Notifications
You must be signed in to change notification settings - Fork 191
Support publishing additional container ports in thv run #3892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ea09ace
87686ac
bc0747e
45115fd
e2d12a7
491d95b
b6bf64a
bab7735
fbc81c3
c7abcce
b386476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,43 @@ func TestGeneratePortBindings_NonAuxiliaryAssignsRandomPortAndMutatesFirstBindin | |
| assert.Equal(t, 1, countMatches, "expected exactly one first binding to be updated to hostPort=%s", expected) | ||
| } | ||
|
|
||
| func TestGeneratePortBindings_NonAuxiliaryKeepsExplicitHostPort(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| labels := map[string]string{} // not auxiliary | ||
| in := map[string][]runtime.PortBinding{ | ||
| "8080/tcp": { | ||
| {HostIP: "", HostPort: "9090"}, | ||
| }, | ||
| } | ||
| out, hostPort, err := generatePortBindings(labels, in) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 9090, hostPort) | ||
|
|
||
| require.Contains(t, out, "8080/tcp") | ||
| require.Len(t, out["8080/tcp"], 1) | ||
| assert.Equal(t, "9090", out["8080/tcp"][0].HostPort) | ||
| } | ||
|
|
||
| func TestGeneratePortBindings_NonAuxiliaryAssignsRandomPortForZero(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| labels := map[string]string{} // not auxiliary | ||
| in := map[string][]runtime.PortBinding{ | ||
| "8080/tcp": { | ||
| {HostIP: "", HostPort: "0"}, | ||
| }, | ||
| } | ||
| out, hostPort, err := generatePortBindings(labels, in) | ||
| require.NoError(t, err) | ||
| require.NotZero(t, hostPort) | ||
|
|
||
| require.Contains(t, out, "8080/tcp") | ||
| require.Len(t, out["8080/tcp"], 1) | ||
| assert.NotEqual(t, "0", out["8080/tcp"][0].HostPort) | ||
| assert.Equal(t, fmt.Sprintf("%d", hostPort), out["8080/tcp"][0].HostPort) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, feel free to ignore: could also assert non-zero
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
| } | ||
|
|
||
| func TestAddEgressEnvVars_SetsAll(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the fix for:
?
If so, can you find a way to add a regression test and some unit tests here? The
generatePortBindingsfunction seems like it should be amenable to unit testing without any refactoring.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added two new regression tests for generatePortBindings to
client_helpers_test.go:TestGeneratePortBindings_NonAuxiliaryKeepsExplicitHostPort: ensures explicit host ports (e.g., "9090") are kept instead of replaced with a random port.TestGeneratePortBindings_NonAuxiliaryAssignsRandomPortForZero: ensures passing "0" correctly assigns a random available port.