-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🏃 tests: move NewWithT(t) to inside the t.Run where applicable #2799
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me for the most part. I've added a couple of suggestions. One being to not have multiple g
s within a subtest and the other about not shadowing. There's a few places where we declare g := NewWith(t)
within the subtest, when there's already a g
within the outer scope, I wonder if it's worth calling the subtest ones gs
instead so it's obvious this gomega is failing the subtest? WDYT? I've tried to highlight all the places I noticed this.
bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go
Outdated
Show resolved
Hide resolved
@@ -890,7 +888,7 @@ func TestKubeadmConfigReconciler_Reconcile_DisocveryReconcileBehaviors(t *testin | |||
name string | |||
cluster *clusterv1.Cluster | |||
config *bootstrapv1.KubeadmConfig | |||
validateDiscovery func(*bootstrapv1.KubeadmConfig) error | |||
validateDiscovery func(g *WithT, kubeAdm *bootstrapv1.KubeadmConfig) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can omit the argument names from the declaration (as it was before) func(*WithT, *bootstrapv1.KubeadmConfig) error
these can be on the side of the definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -110,6 +110,8 @@ func TestControlPlaneInitMutex_Lock(t *testing.T) { | |||
for _, tc := range tests { | |||
tc := tc | |||
t.Run(tc.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for using gs
here instead of g
?
is the original g
near the function prolog needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a suggestion of mine as there is a g
in the outer scope that this was then shadowing, thought it might make it more obvious to use a different name for the variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the parent g
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the cases where gs
is used, yes, the parent g
is required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for the reason that Joel explained
@@ -192,6 +194,8 @@ func TestControlPlaneInitMutex_UnLock(t *testing.T) { | |||
for _, tc := range tests { | |||
tc := tc | |||
t.Run(tc.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -73,18 +73,20 @@ func Test_viperReader_Get(t *testing.T) { | |||
} | |||
for _, tt := range tests { | |||
t.Run(tt.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -122,15 +124,17 @@ func Test_viperReader_Set(t *testing.T) { | |||
} | |||
for _, tt := range tests { | |||
t.Run(tt.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -462,19 +462,21 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) { | |||
} | |||
for _, tt := range tests { | |||
t.Run(tt.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -61,11 +61,13 @@ func Test_newRepositoryClient_LocalFileSystemRepository(t *testing.T) { | |||
} | |||
for _, tt := range tests { | |||
t.Run(tt.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -94,28 +94,33 @@ func TestNewClusterClient(t *testing.T) { | |||
g.Expect(scheme.AddToScheme(testScheme)).To(Succeed()) | |||
ctx := context.Background() | |||
t.Run("cluster with valid kubeconfig", func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -236,6 +234,8 @@ func TestUpdateKubeProxyImageInfo(t *testing.T) { | |||
|
|||
for _, tt := range tests { | |||
t.Run(tt.name, func(t *testing.T) { | |||
gs := NewWithT(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on this change as NewWithT is supposed to be scoped and cheap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just re-reviewed now you've fixed up the comments I made @cpanato, I'm happy with this once https://github.com/kubernetes-sigs/cluster-api/pull/2799/files#r399301885 is addressed 🙂
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cpanato, neolit123 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@JoelSpeed done the change. PTAL :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! LGTM, thanks @cpanato
/lgtm
/milestone v0.3.3 |
What this PR does / why we need it:
move NewWithT(t) to inside the t.Run where applicable
/kind cleanup
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):g:=NewWithT(t)
to be inside thet.Run
#2798cc @wfernandes @fabriziopandini