argoproj-labs / argocd-operator

A Kubernetes operator for managing Argo CD clusters.
https://argocd-operator.readthedocs.io
Apache License 2.0
595 stars 622 forks source link

Refactor unit tests to make use of github.com/stretchr/testify #302

Open jannfis opened 3 years ago

jannfis commented 3 years ago

Is your task related to a problem? Please describe.

Currently, we are using a lot of code in the unit tests for evaluating outcomes in our unit tests, such as reflect.DeepEqual in if/else branch constructs to trigger t.Errorf() and the likes. This makes writing good unit tests quite a burden.

Describe the solution you'd like

Argo CD uses github.com/stretchr/testify for its unit tests, which is a quite flexible and convenient way to describe assertions on the expected test results, which also has nice output on failures.

We should refactor our unit tests to make use of this framework.

Describe alternatives you've considered

None really.

iam-veeramalla commented 3 years ago

Found a nice and well elaborated comparisons of the most popular options: https://bmuschko.com/blog/go-testing-frameworks/

Can we also consider BDD testing options like ginkgo/gomega ? @jannfis

jannfis commented 3 years ago

Thanks for that link, @iam-veeramalla, it's a great summary.

And sure, I think it's a great idea to explore possible other options. I'm only a little opinionated on testify, since its used in other Argo CD sub-projects already and is quite lightweight and very easy to use. But maybe we can pick up a set of certain existing unit tests and try to model them in various frameworks, to see how it will fit. WDYT?

iam-veeramalla commented 3 years ago

@jannfis sure .. That would be great !!

jannfis commented 2 years ago

First chunk of migration to stretchr/testify can be seen in https://github.com/argoproj-labs/argocd-operator/pull/437