Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
christarazi opened this issue Jul 12, 2021 · 6 comments
Labels
area/CI Continuous Integration testing issue or flake kind/evaluate This needs consideration of the scope and impact of the change. pinned These issues are not marked stale by our issue bot.

Comments

@christarazi
Copy link
Member

christarazi commented Jul 12, 2021

(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 christarazi added area/CI Continuous Integration testing issue or flake kind/evaluate This needs consideration of the scope and impact of the change. labels Jul 12, 2021
@christarazi
Copy link
Member Author

christarazi commented Jul 12, 2021

(Feel free to edit to update)

Std Go style:

Pros:

  • More active development
  • Subtest support
  • Simpler and more familiar with the average Go developer

Cons:

  • Lacks consistency in terms of patterns (up to developer to write the comparisons)
    • Mitigation is to use go-cmp or testify
  • Lacks setup / teardown funcs

gochecker:

Pros:

  • All-in-one experience (setup / teardown, asserts, comparisons helpers)

Cons:

  • Lagging behind in upstream features like subtest support
  • Requires learning yet another framework
  • More boilerplate code for simple tests that don't require a whole setup/teardown

@christarazi christarazi changed the title Standard Go style unit testing via testing and go-checker framework currently used Unit testing framework discussion: standard Go style unit testing via testing and go-checker framework Jul 12, 2021
@gandro
Copy link
Member

gandro commented Jul 13, 2021

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 (#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.

@christarazi christarazi mentioned this issue Sep 17, 2021
9 tasks
@ldelossa
Copy link
Contributor

ldelossa commented Sep 28, 2021

@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
Copy link
Member Author

I think it makes sense to keep open for visibility.

@github-actions
Copy link

github-actions bot commented Jul 9, 2022

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

@github-actions github-actions bot added the stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale. label Jul 9, 2022
@christarazi christarazi added pinned These issues are not marked stale by our issue bot. and removed stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale. labels Jul 12, 2022
@xmulligan
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CI Continuous Integration testing issue or flake kind/evaluate This needs consideration of the scope and impact of the change. pinned These issues are not marked stale by our issue bot.
Projects
None yet
Development

No branches or pull requests

4 participants