Skip to content

feat: support optional arguments for int/uint/float types#747

Open
chengxilo wants to merge 1 commit into
cucumber:mainfrom
chengxilo:support-optional
Open

feat: support optional arguments for int/uint/float types#747
chengxilo wants to merge 1 commit into
cucumber:mainfrom
chengxilo:support-optional

Conversation

@chengxilo
Copy link
Copy Markdown
Contributor

@chengxilo chengxilo commented May 30, 2026

🤔 What's changed?

This would support int/uint/float pointer as parameter in step functions

⚡️ What's your motivation?

I'm a contributor to Apache iggy, I'm planning to add a BDD test scenario for it.
Here is the use case I have:

I have the following steps for different sceanarios.

    Given I have a running Iggy server whose network may be disrupted
    And reconnection is enabled with 3 retries and 2 seconds interval
    Given I have a running Iggy server whose network may be disrupted
    And reconnection is disabled
    Given I have a running Iggy server whose network may be disrupted
    And reconnection is enabled

Currently, this is what I'm doing

func (s reconnectSteps) setReconnection(ctx context.Context, state string, retries string, interval string) error {
	c := getReconnectCtx(ctx)

	enable := state == "enabled"
	var opts []tcp.ReconnectionOption

	// TODO: currently godog doesn't support optional int/uint parameters, change to proper optional parameters once godog supports it
	if retries != "" {
		maxRetries, _ := strconv.ParseUint(retries, 10, 32)
		opts = append(opts, tcp.WithMaxRetries(uint32(maxRetries)))
	}
	if interval != "" {
		secs, _ := strconv.Atoi(interval)
		opts = append(opts, tcp.WithRetryInterval(time.Duration(secs)*time.Second))
	}

	if !enable && len(opts) != 0 {
		return fmt.Errorf("reconnection disabled but other options are provided, this test case is invalid")
	}

	c.tcpOpts = append(c.tcpOpts, tcp.WithReconnection(enable, opts...))
	return nil
}
sc.Step(`^reconnection is (enabled|disabled)(?: with (\d+) retries and (\d+) seconds interval)?$`, s.setReconnection)

I hate to do parse the string to uint/int when writing my test, so I hope I can support optional parameter using pointer in godog.

Here is what my function would be like if this feature is implemented.

func (s reconnectSteps) setReconnection(ctx context.Context, state string, retries *uint32, interval *int) error

I don't want to

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

📋 Checklist:

I'm not sure if this would be accepted, so I will delay adding the document (since I hate writing), also the CHANGELOG.md

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

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