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

Remove the BMCClient interface, ginkgo, and gomega #102

Merged
merged 6 commits into from
May 11, 2023

Conversation

jacobweinstock
Copy link
Member

@jacobweinstock jacobweinstock commented May 5, 2023

Description

Why is this needed

The BMCClient interface was unnecessary and added complexity to testing. bmclib already has the capabilities to specify mock providers. Removing this interface also allowed us to remove ginkgo and gomega. These frameworks were unneeded and overly complex. This PR simplifies tests, increases coverage, and sets us up to build out more tests quickly and simply.

Fixes: #59

How Has This Been Tested?

How are existing users impacted? What migration steps/scripts do we need?

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #102 (ae0ada1) into main (458449e) will increase coverage by 3.71%.
The diff coverage is 57.44%.

❗ Current head ae0ada1 differs from pull request most recent head 40bb987. Consider uploading reports for the commit 40bb987 to get more accurate results

@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
+ Coverage   58.85%   62.57%   +3.71%     
==========================================
  Files           4        4              
  Lines         350      350              
==========================================
+ Hits          206      219      +13     
+ Misses        107       97      -10     
+ Partials       37       34       -3     
Impacted Files Coverage Δ
controllers/client.go 0.00% <0.00%> (ø)
controllers/job.go 55.28% <57.14%> (ø)
controllers/task.go 63.93% <70.37%> (ø)
controllers/machine.go 80.21% <83.33%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@chrisdoherty4 chrisdoherty4 left a comment

Choose a reason for hiding this comment

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

Some great improvements. Glad to be removing Ginkgo.

for name, tt := range map[string]struct {
configureClientCalls func(expect *mocks.MockBMCClientMockRecorder)
action v1alpha1.Action
func TestTaskReconcile(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

The body of the test func has a lot going on. I'm not sure it helps understandability compared to breaking into a few separate table tests. For example, there seems to be different test branches such as the t.timeoutErr that might help readability if it were a separate top level test.

What's the motivation to bundle all tests into a single table test?

Copy link
Member Author

@jacobweinstock jacobweinstock May 8, 2023

Choose a reason for hiding this comment

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

this was mostly a translation of the ginkgo/gomega tests. The idea was to start by removing those libs and then refactoring the tests. I can do the refactor in this PR if you'd like.

type Job struct {
metav1.TypeMeta `json:",inline"`
Copy link
Member

Choose a reason for hiding this comment

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

I'm weary of removing inline because every object I've ever seen does it. I'm not 100%, but I think its an option used by Kubernetes client-go json/yaml implementation. Its also documented in examples in the kubebuilder book https://book.kubebuilder.io/cronjob-tutorial/new-api.html.

Copy link
Member Author

@jacobweinstock jacobweinstock May 8, 2023

Choose a reason for hiding this comment

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

inline is not a recognized struct tag in Go. I believe the only reason to keep them is if we have any code generation that depends on it. I ran make generate and make manifests and don't think I saw any issues. I could be mistaken though.

ref:
golang/go#6213
kubernetes/kubernetes#117206

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, this has plagued me with the linting and I could never find anything useful about it.

}

func (r *JobReconciler) reconcile(ctx context.Context, job *bmcv1alpha1.Job, jobPatch client.Patch, logger logr.Logger) (ctrl.Result, error) {
func (r *JobReconciler) doReconcile(ctx context.Context, job *v1alpha1.Job, jobPatch client.Patch) (ctrl.Result, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the do prefix? do prefixes don't really add anything.

Copy link
Member Author

@jacobweinstock jacobweinstock May 8, 2023

Choose a reason for hiding this comment

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

this was a linting issue that came up. I'm open to changing this. I can revert back and add a notlint or change the name entirely or see about removing the check from the lint config. Thoughts?

secret *corev1.Secret
job *v1alpha1.Job
shouldErr bool
testAll bool
Copy link
Member

Choose a reason for hiding this comment

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

What are the semantics of testAll?

Copy link
Member Author

Choose a reason for hiding this comment

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

testAll allows this test to do more testing than just if reconciler.Reconcile was successful. This is an artifact of translating the ginkgo/gomega tests. I will refactor, just depends on if you would like that done in this PR or a follow-up. This PR is fairly large as is.

controllers/job_test.go Outdated Show resolved Hide resolved
@chrisdoherty4 chrisdoherty4 added the ready-to-merge Mergify: Ready for Merging label May 10, 2023
@chrisdoherty4
Copy link
Member

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented May 10, 2023

queue

🛑 The pull request has been removed from the queue

Pull request #102 has been dequeued due to failing checks or checks timeout.

You can take a look at Queue: Embarked in merge train check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

This makes it easier to run the linting. And
ci will run the exact same linting.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
The BMCClient interface was unnecessary and added
complexity to testing. bmclib already has the capabilities
to specify mock providers. Removing this interface also
allowed us to remove ginkgo and gomega. These frameworks
were unneeded and overly complex.

Also fixed all linting errors.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
Files in the controller package are already
namespaced and don't need "_controller" in their
name.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
The lines were a bit long for reading.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
@jacobweinstock
Copy link
Member Author

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented May 11, 2023

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 219cdd4

@mergify mergify bot merged commit 219cdd4 into tinkerbell:main May 11, 2023
@jacobweinstock jacobweinstock deleted the remove-bmcclient-interface branch May 11, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Mergify: Ready for Merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Ginkgo/Gomega
2 participants