Skip to content

Conversation

@hwdef
Copy link
Contributor

@hwdef hwdef commented Jul 3, 2025

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hwdef
Once this PR has been reviewed and has the lgtm label, please assign ahrtr for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link

Hi @hwdef. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@siyuanfoundation
Copy link
Contributor

/ok-to-test


// KV

type kvStub struct{}
Copy link
Contributor

@siyuanfoundation siyuanfoundation Jul 10, 2025

Choose a reason for hiding this comment

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

we need to think about how to pass in the mock response.
Like a fake dict of kvs, a list of alarms.

Can you try to use the fakeclient to test alarm_command as an example of how it should work?

@codecov
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

❌ Patch coverage is 64.04494% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.61%. Comparing base (584c7cc) to head (983a7ad).

Files with missing lines Patch % Lines
etcdctl/ctlv3/command/fakeclient/client.go 32.25% 21 Missing ⚠️
etcdctl/ctlv3/command/global.go 81.81% 5 Missing and 3 partials ⚠️
etcdctl/ctlv3/command/test_utils.go 84.61% 1 Missing and 1 partial ⚠️
etcdctl/ctlv3/ctl.go 0.00% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
etcdctl/ctlv3/ctl.go 0.00% <0.00%> (ø)
etcdctl/ctlv3/command/test_utils.go 84.61% <84.61%> (ø)
etcdctl/ctlv3/command/global.go 52.17% <81.81%> (+52.17%) ⬆️
etcdctl/ctlv3/command/fakeclient/client.go 32.25% <32.25%> (ø)

... and 27 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #20270      +/-   ##
==========================================
+ Coverage   69.16%   69.61%   +0.44%     
==========================================
  Files         422      424       +2     
  Lines       34841    34907      +66     
==========================================
+ Hits        24098    24300     +202     
+ Misses       9339     9162     -177     
- Partials     1404     1445      +41     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 584c7cc...983a7ad. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch from 6f0f3ff to e050fdb Compare August 13, 2025 04:26
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch 4 times, most recently from 34dcb55 to ca8b054 Compare August 13, 2025 07:44
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch from ca8b054 to abab404 Compare August 21, 2025 10:24
@hwdef hwdef marked this pull request as draft August 21, 2025 10:59
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch from abab404 to 4cd9111 Compare August 27, 2025 08:59
@hwdef hwdef marked this pull request as ready for review August 27, 2025 09:11
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch 3 times, most recently from 4d76620 to 21d330d Compare August 27, 2025 10:01
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch 3 times, most recently from 0eb3dff to 364b200 Compare September 4, 2025 12:30
@hwdef
Copy link
Contributor Author

hwdef commented Sep 9, 2025

@siyuanfoundation @Elbehery @serathius
PTAL. This PR is ready for review :)

@siyuanfoundation
Copy link
Contributor

Overall this approach works.
But if the tests run in parallel, there will be race condition on the var newClientFunc. To ensure only 1 test runs at a time, we will need to add a new test suite in test.sh with go test -p 1.

Another option would be refactor all the functions like NewAlarmCommand to take a client argument. Personally I would prefer this.

@ahrtr would really appreciate your input. Thanks!

@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch 2 times, most recently from 39b15be to 4bb7e7b Compare October 14, 2025 06:14
@hwdef
Copy link
Contributor Author

hwdef commented Oct 14, 2025

/retest

@hwdef
Copy link
Contributor Author

hwdef commented Oct 21, 2025

PTAL @ahrtr @Elbehery

func newTestRoot() *cobra.Command {
root := &cobra.Command{Use: "etcdctl"}
root.AddGroup(NewKVGroup(), NewClusterMaintenanceGroup(), NewConcurrencyGroup(), NewAuthenticationGroup(), NewUtilityGroup())
root.PersistentFlags().StringSlice("endpoints", []string{"127.0.0.1:2379"}, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

abstract to a function shared with init()

"go.etcd.io/etcd/etcdctl/v3/ctlv3/command/fakeclient"
)

func withStdoutCapture(t *testing.T, fn func()) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

move this and setupFake to a separate file like test_utils.go

@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch 5 times, most recently from f57b429 to 6634073 Compare December 4, 2025 04:11
@hwdef hwdef force-pushed the etcdctl-ut-fakeclient branch from 6634073 to 983a7ad Compare December 4, 2025 04:34

// GlobalFlags are flags that defined globally
// and are inherited to all sub-commands.
type GlobalFlags struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this struct is not very useful to begin with. How about moving the refactor to a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check unused flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants