Skip to content

refactor/wgcf/optional-keepalive-generation - #637

Open
michaelik1 wants to merge 4 commits into
ViRb3:masterfrom
michaelik1:refactor/wgcf/optional-keepalive-generation
Open

michaelik1 wants to merge 4 commits into
ViRb3:masterfrom
michaelik1:refactor/wgcf/optional-keepalive-generation

Conversation

@michaelik1

Copy link
Copy Markdown
Contributor

Motivation

The current --keepalive flag uses NoOptDefVal to default to 25 when no value is provided. However, this introduces inconsistent behavior between the two common ways of passing flag values.

For example:

  • --keepalive uses the implicit value of 25.
  • --keepalive=25 explicitly sets the value to 25.
  • --keepalive 25 uses the implicit value of 25, while 25 is treated as a positional argument rather than the flag's value.

This behavior can be confusing, especially since other flags support both the equals and space-separated syntax.

Description

Removes NoOptDefVal from the --keepalive flag, making its value explicitly required whenever the flag is specified.

Usage:

wgcf generate --keepalive     # Error: flag needs an argument
wgcf generate --keepalive=25  # Sets keepalive to 25
wgcf generate --keepalive 25  # Sets keepalive to 25

The default remains 0 when the flag is omitted.

The equals syntax remains unchanged, preserving compatibility with the usage documented in the README. However, invoking --keepalive without a value will now produce an error instead of implicitly using 25.

Tests

  • Updated generate_test.go to use table-driven tests covering both flag syntaxes, missing values, and invalid inputs.
  • Removed the redundant TestGenerateProfileWithCustomKeepalive test from profile_test.go, as it assumed that PersistentKeepalive would always be the last line of the generated profile. This ordering is not guaranteed, and the remaining test already verifies the complete profile content.

@ViRb3

- rewrite TestKeepaliveFlag using maintainer's way of testing with tests struct
- resetFlag helper function introduced in PR ViRb3#634;
The test assumed that PersistentKeepalive would always be the last line in the generated profile, which is not guaranteed. The existing test that verifies the full profile content already covers this case.
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.

1 participant