cilium / cilium

eBPF-based Networking, Security, and Observability
https://cilium.io
Apache License 2.0
19.95k stars 2.93k forks source link

Unit testing framework discussion: standard Go style unit testing via `testing` and `go-checker` framework #16860

Open christarazi opened 3 years ago

christarazi commented 3 years ago

(Copied from https://cilium.slack.com/archives/C2B917YHE/p1626113446459700)

In the Cilium codebase, we heavily use https://github.com/go-check/check/tree/v1 as the unit testing framework. I've been increasingly feeling like we don't quite need this framework anymore because the std Go testing package + other small convenience packages for asserting is sufficient.

FWIW, pkg/hubble is written using the std Go style instead of gocheck.

How do people feel about this?

In terms of adoption, one approach would be to add new tests using the std Go style and over time we gradually move away from gocheck. Not advocating for a rewrite immediately.

Used for tracking pros and cons, and capturing other discussions because Slack will lose history

christarazi commented 3 years ago

(Feel free to edit to update)

Std Go style:

Pros:

Cons:

gochecker:

Pros:

Cons:

gandro commented 3 years ago

FWIW, pkg/hubble is written using the std Go style instead of gocheck.

To expand on that, this is due to most code of this package originally being developed out of tree. We noticed the discrepancy at the time, but decided it was much work and not much benefit in moving all code to gochecker, so we stuck to the Std Go style for that package.

We did run into issues with testify (https://github.com/cilium/cilium/issues/12772), so parts of it now use go-cmp instead. I'm not sure if the underlying issue was ever fixed though, it doesn't look like it is.

ldelossa commented 3 years ago

@christarazi I believe we came to an agreement on this ticket. We came to the decision that new code will use the std-library testing package with go-cmp in addition when comparison is necessary.

We won't be "re-writing" any tests which exist today to conform to this, and this decision is for subsequent new code.

Should this ticket remain open?

christarazi commented 3 years ago

I think it makes sense to keep open for visibility.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

xmulligan commented 1 year ago

From @lmb in slack

The PR is here, and contains some context why this change is necessary / useful. this is a tree-wide change and so has the possibility to impact a bunch of people, so i want to raise awareness here. i'm planning to get this merged next wednesday-ish, 2023-05-24. the following things will change: gocheck specific flags like -check.f and so on are going away. just use the normal go test -run. the name of specific tests will change, for example MySuite.TestSomeBehaviour will become MySuite/TestSomeBehaviour. the output format will be closer to the standard go test output. some APIs of gocheck have been deprecated or removed (as long as there was no use in the cilium codebase). details are here. please let me know if you think that this change might impact you negatively!