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

🏃 tests: move NewWithT(t) to inside the t.Run where applicable #2799

Merged
merged 1 commit into from
Mar 27, 2020

Conversation

cpanato
Copy link
Member

@cpanato cpanato commented Mar 27, 2020

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):

cc @wfernandes @fabriziopandini

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 27, 2020
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 27, 2020
Copy link
Contributor

@JoelSpeed JoelSpeed left a 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 gs 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.

cmd/clusterctl/client/config/reader_viper_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/config_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/repository/components_client_test.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/repository/client_test.go Outdated Show resolved Hide resolved
controllers/machineset_controller_test.go Outdated Show resolved Hide resolved
controllers/remote/cluster_test.go Outdated Show resolved Hide resolved
controlplane/kubeadm/internal/workload_cluster_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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok sgtm

Copy link
Member Author

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)
Copy link
Member

@neolit123 neolit123 Mar 27, 2020

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?

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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 parent g?

Copy link
Contributor

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

Copy link
Member Author

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

Copy link
Member

@neolit123 neolit123 left a 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.

Copy link
Contributor

@JoelSpeed JoelSpeed left a 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 🙂

@neolit123
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2020
@cpanato
Copy link
Member Author

cpanato commented Mar 27, 2020

@JoelSpeed done the change. PTAL :)

Copy link
Contributor

@JoelSpeed JoelSpeed left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2020
@k8s-ci-robot k8s-ci-robot merged commit 1717c75 into kubernetes-sigs:master Mar 27, 2020
@cpanato cpanato deleted the GH-2798 branch March 27, 2020 15:11
@vincepri
Copy link
Member

/milestone v0.3.3

@k8s-ci-robot k8s-ci-robot added this to the v0.3.3 milestone Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move g:=NewWithT(t) to be inside the t.Run
5 participants