⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@microness
Copy link

related: #4613

assert.Equal(t, iptablesutil.ForwardExists(t, ipt, chain, containerIP, hostPort), true)

base.Cmd("kill", testContainerName).AssertOK()
assert.Equal(t, iptablesutil.ForwardExists(t, ipt, chain, containerIP, hostPort), false)
Copy link
Member

Choose a reason for hiding this comment

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

@microness I found the refactoring dropped a check "iptables rule removed after kill". Would you mind adding the post-kill validation?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comment! Fixed.

t.Skip("pkg/testutil/iptables does not support rootless")
}

const hostPort = 9999
Copy link
Member

Choose a reason for hiding this comment

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

IMO, instead of hard-coding the port number, it is better to use the port number acquired via portlock.Acquire(). So, could you rewrite it?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comment! Fixed.

Comment on lines 40 to 43
// skip if rootless
if rootlessutil.IsRootless() {
t.Skip("pkg/testutil/iptables does not support rootless")
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comment! Fixed.

},
}

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add logic to release the acquired port number?

		if p := data.Labels().Get("hostPort"); p != "" {
			if port, err := strconv.Atoi(p); err == nil {
				_ = portlock.Release(port)
			}
		}

hostPort, _ := strconv.Atoi(data.Labels().Get("hostPort"))
chain := data.Labels().Get("chain")

assert.Equal(t, iptablesutil.ForwardExists(t, ipt, chain, containerIP, hostPort), true)
Copy link
Member

Choose a reason for hiding this comment

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

Testing it within the Setup seems odd—couldn't we implement it using helper.Custom?

Copy link
Author

@microness microness Jan 15, 2026

Choose a reason for hiding this comment

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

Thanks for the comments!

I’ve fixed on your feedback and have a few questions.
I’d appreciate a re-review.

Q1. Using helpers.Custom in Setup

I also felt that putting assert.Assert directly in Setup was a bit awkward,
So I refactored it with helpers.Custom as suggested below.

// Description: "iptables forwarding rule should exist before container is killed"

// Setup:
helpers.Custom(
	"iptables",
	"-t", "nat",
	"-S", chain,
).Run(&test.Expected{
	ExitCode: expect.ExitCodeSuccess,
	Output: func(stdout string, t tig.T) {
		assert.Assert(t, strings.Contains(stdout, fmt.Sprintf("--dport %d", hostPort)))
		assert.Assert(t, strings.Contains(stdout, "DNAT"))
		assert.Assert(t, strings.Contains(stdout, containerIP))
	},
})

According to the documentation, helpers can be used in all phases including Setup and Cleanup.

// Helpers provides a set of helpers to run commands with simple expectations,
// available at all stages of a test (Setup, Cleanup, etc...)
type Helpers interface {

Does that mean using helpers.Custom in Setup is acceptable in your view?

Q2. Using iptablesutil.ForwardExists vs helpers.Custom with iptables command

For the same reason, I replaced iptablesutil.ForwardExists with a helpers.Custom with iptables command.
Do you think this is a better fit for Setup, or would you prefer keeping the iptablesutil?

Thanks again for the review, I learned a lot.

@microness microness force-pushed the issues_4613_container_kill_linux_test.go branch from e195486 to 1529fad Compare January 15, 2026 18:03
@microness microness changed the title test: refactor container_kill_linux_Test.go to use Tigron test: refactor container_kill_linux_test.go to use Tigron Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants