test: remove a new line from containerID for correct test execution#4801
Open
haytok wants to merge 1 commit intocontainerd:mainfrom
Open
test: remove a new line from containerID for correct test execution#4801haytok wants to merge 1 commit intocontainerd:mainfrom
haytok wants to merge 1 commit intocontainerd:mainfrom
Conversation
When running `TestContainerRmIptables` with verbose output, the following`
error can be observed:
```
$ sudo go test -run TestContainerRmIptables -v
...
=== CONT TestContainerRmIptables/Test_iptables_rules_are_cleared_after_container_deletion
container_remove_linux_test.go:135:
...
container_remove_linux_test.go:49:
+------------------------------------------------------------------------------------------------------------+
| ➡️ | ⚙️ /usr/local/bin/nerdctl rm -f fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504 |
| | |
+------------------------------------------------------------------------------------------------------------+
| | 🟠 time="2026-03-23T00:00:53+09:00" level=error msg="1 errors:\nfilters: parse error: [labels.\" |
| | nerdctl/name\"==fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504 >|\n|< ]: unexp |
| | ected input: \n: invalid argument: invalid argument" |
...
container_remove_linux_test.go:135:
<<<<<<<<<<<<<<<<<<<<
🖊️ Inspecting output (does not contain)
👀 testing: `-P PREROUTING ACCEPT
-P INPUT ACCEPT
...
-A POSTROUTING -s 10.4.0.148/32 -m comment --comment "name: \"bridge\" id: \"nerdctl-test-fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504\"" -j CNI-d4bd64738075587aa8d84afc
...
-A CNI-HOSTPORT-DNAT -p tcp -m comment --comment "dnat name: \"bridge\" id: \"nerdctl-test-fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504\"" -m multiport --dports 5000 -j CNI-DN-d4bd64738075587aa8d84
...
-A CNI-d4bd64738075587aa8d84afc -d 10.4.0.0/24 -m comment --comment "name: \"bridge\" id: \"nerdctl-test-fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504\"" -j ACCEPT
-A CNI-d4bd64738075587aa8d84afc ! -d 224.0.0.0/4 -m comment --comment "name: \"bridge\" id: \"nerdctl-test-fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504\"" -j MASQUERADE
...
-P POSTROUTING ACCEPT
`
✅️ does verify: ! ~= `fd4fc99e04476d7f673133a06338933aadc547d4eef883f469464d7d31467504
`
>>>>>>>>>>>>>>>>>>>>
...
=== NAME TestContainerRmIptables
container_remove_linux_test.go:135:
+============================================================================================================+
| 🧽 | "TestContainerRmIptables": post-cleanup |
+============================================================================================================+
--- PASS: TestContainerRmIptables (0.00s)
--- PASS: TestContainerRmIptables/Test_iptables_rules_are_cleared_after_container_deletion (2.93s)
PASS
ok github.com/containerd/nerdctl/v2/cmd/nerdctl/container 2.936s
```
The error `unexpected input: \n: invalid argument: invalid argument`
indicates that the container is not being removed correctly.
Additionally, since the container ID remains in the iptables output, it
is clear that `expect.DoesNotContain(containerID)` passes for the wrong
reason, and the test is not properly validating the iptables cleanup
behavior after container removal.
This commit removes the new line from the container ID using `strings.TrimSpace`.
Signed-off-by: Hayato Kiwata <dev@haytok.jp>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When running
TestContainerRmIptableswith verbose output, the following error can be observed:The error
unexpected input: \n: invalid argument: invalid argumentindicates that the container is not being removed correctly.Additionally, since the container ID remains in the iptables output, it is clear that
expect.DoesNotContain(containerID)passes for the wrong reason, and the test is not properly validating the iptables cleanup behavior after container removal.This commit removes the new line from the container ID using
strings.TrimSpace.