Skip to content

daemon/links: use gotest.tools, remove unneeded utility and duplicated test#49232

Merged
thaJeztah merged 5 commits intomoby:masterfrom
thaJeztah:link_test_cleanup
Jan 8, 2025
Merged

daemon/links: use gotest.tools, remove unneeded utility and duplicated test#49232
thaJeztah merged 5 commits intomoby:masterfrom
thaJeztah:link_test_cleanup

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

relates to:

daemon/links: remove newPortNoError utility

This utility was added in 12b6083 as a
replacement for nat.NewPort(), which before that patch would panic on
invalid values, but was changed to return an error.

Given that the utility ignores any error, and these values are fixed values
for the test, let's remove it to simplify constructing the tests.

daemon/links: TestLinkNew: assert with gotest.tools

daemon/links: TestLinkNaming: assert with gotest.tools

Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

daemon/links: TestLinkEnv: assert with gotest.tools

Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

daemon/links: TestLinkMultipleEnv: assert with gotest.tools, remove TestLinkPortRangeEnv

Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

TestLinkPortRangeEnv was added in 611a23a
to test for port-ranges to produce the expected env-vars, but used the
same input as TestLinkMultipleEnv. Now that we assert all env-vars produced,
it became a duplicate of TestLinkMultipleEnv, so we can remove that test.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

This utility was added in 12b6083 as a
replacement for nat.NewPort(), which before that patch would panic on
invalid values, but was changed to return an error.

Given that the utility ignores any error, and these values are fixed values
for the test, let's remove it to simplify constructing the tests.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
…estLinkPortRangeEnv

Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.

TestLinkPortRangeEnv was added in 611a23a
to test for port-ranges to produce the expected env-vars, but used the
same input as TestLinkMultipleEnv. Now that we assert all env-vars produced,
it became a duplicate of TestLinkMultipleEnv, so we can remove that test.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added status/2-code-review area/testing kind/refactor PR's that refactor, or clean-up code labels Jan 8, 2025
@thaJeztah thaJeztah added this to the 28.0.0 milestone Jan 8, 2025
@thaJeztah thaJeztah self-assigned this Jan 8, 2025
Comment on lines +35 to +42
expected := &Link{
Name: "/db/docker",
ParentIP: "172.0.17.3",
ChildIP: "172.0.17.2",
Ports: []nat.Port{"6379/tcp"},
}

assert.DeepEqual(t, expected, link)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; this is roughly how I arrived in this package; the Link type is not used anywhere, and it's only used as an intermediate struct to produce the env-vars to set.

I may be rewriting some code so that the scope of the package is reduced to only generating env-vars and internalise the Link type.

Comment on lines +77 to +78
"DOCKER_PORT_6379_TCP_ADDR=172.0.17.2",
"DOCKER_PORT_6379_TCP_ADDR=172.0.17.2", // FIXME(thaJeztah): duplicate?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this was a fun discovery when I rewrote the test; looks like a bug, likely introduced in #10061 resulting in the same linux/port being processed multiple times, causing duplicate env-vars.

Not problematic, as they will be ignored when creating the container, but still probably a bug.

@thaJeztah thaJeztah changed the title daemon/links: use gotest.tools, remove unneeded utility and duplicate test daemon/links: use gotest.tools, remove unneeded utility and duplicated test Jan 8, 2025
@thaJeztah thaJeztah merged commit 53287e4 into moby:master Jan 8, 2025
@thaJeztah thaJeztah deleted the link_test_cleanup branch January 8, 2025 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants