From 45ebf2504bcdf4eb5b9f7743b3f563af684f4429 Mon Sep 17 00:00:00 2001 From: Anusha Hegde Date: Tue, 18 Jan 2022 03:38:34 +0000 Subject: [PATCH 1/2] Enable testpackage linter - update .golangci.yml - fix lint errors for testpackage and gocritic - add nolint annotation wherever significant code change is required --- .golangci.yml | 2 +- agent/cloudinit/cloudinit_integration_test.go | 12 ++++----- agent/cloudinit/file_writer_test.go | 27 ++++++++++--------- agent/help_flag_test.go | 1 + agent/host_agent_suite_test.go | 1 + agent/host_agent_test.go | 1 + agent/installer/bundle_downloader_test.go | 1 + agent/installer/installer_suite_test.go | 1 + agent/installer/installer_test.go | 1 + .../internal/algo/algo_suite_test.go | 1 + agent/installer/internal/algo/algo_test.go | 1 + agent/installer/os_detector.go | 1 + agent/installer/os_detector_test.go | 1 + agent/installer/registry_test.go | 1 + agent/label_flag_test.go | 1 + .../v1beta1/byocluster_webhook_test.go | 17 ++++++------ .../v1beta1/byohost_webhook_test.go | 15 ++++++----- .../v1beta1/webhook_suite_test.go | 11 ++++---- .../infrastructure/byomachine_controller.go | 4 +-- .../byomachine_controller_test.go | 15 ++++++----- controllers/infrastructure/suite_test.go | 7 ++--- test/e2e/byohost_reuse_test.go | 1 + test/e2e/e2e_debug_helper.go | 3 +-- test/e2e/e2e_suite_test.go | 1 + test/e2e/e2e_test.go | 1 + test/e2e/md_scale_test.go | 1 + 26 files changed, 75 insertions(+), 54 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1c26d425c..0f1213ad8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,6 +39,7 @@ linters: - staticcheck - structcheck - stylecheck + - testpackage - typecheck - unconvert # - unparam @@ -59,7 +60,6 @@ linters: # - lll # - nestif # - prealloc - # - testpackage # - revive # - scopelint # - wsl diff --git a/agent/cloudinit/cloudinit_integration_test.go b/agent/cloudinit/cloudinit_integration_test.go index 6fbec265a..afd73454d 100644 --- a/agent/cloudinit/cloudinit_integration_test.go +++ b/agent/cloudinit/cloudinit_integration_test.go @@ -55,7 +55,7 @@ runCmd: err := scriptExecutor.Execute(cloudInitScript) Expect(err).ToNot(HaveOccurred()) - fileContents, errFileContents := ioutil.ReadFile(fileName) + fileContents, errFileContents := os.ReadFile(fileName) Expect(errFileContents).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(fileNewContent)) }) @@ -67,7 +67,7 @@ runCmd: filePermission := 0777 isAppend := true - err := ioutil.WriteFile(fileName, []byte(fileOriginContent), 0644) + err := os.WriteFile(fileName, []byte(fileOriginContent), 0644) Expect(err).NotTo(HaveOccurred()) cloudInitScript := fmt.Sprintf(`write_files: @@ -79,7 +79,7 @@ runCmd: err = scriptExecutor.Execute(cloudInitScript) Expect(err).ToNot(HaveOccurred()) - fileContents, errFileContents := ioutil.ReadFile(fileName) + fileContents, errFileContents := os.ReadFile(fileName) Expect(errFileContents).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(fileOriginContent + fileAppendContent)) @@ -101,7 +101,7 @@ runCmd: err := scriptExecutor.Execute(cloudInitScript) Expect(err).ToNot(HaveOccurred()) - fileContents, err := ioutil.ReadFile(fileName) + fileContents, err := os.ReadFile(fileName) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(fileContent)) }) @@ -121,7 +121,7 @@ runCmd: err = scriptExecutor.Execute(cloudInitScript) Expect(err).ToNot(HaveOccurred()) - fileContents, err := ioutil.ReadFile(fileName) + fileContents, err := os.ReadFile(fileName) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(fileContent)) }) @@ -138,7 +138,7 @@ runCmd: err := scriptExecutor.Execute(cloudInitScript) Expect(err).ToNot(HaveOccurred()) - fileContents, err := ioutil.ReadFile(fileName) + fileContents, err := os.ReadFile(fileName) Expect(err).ToNot(HaveOccurred()) Expect(string(fileContents)).To(Equal(replacedFileContent)) }) diff --git a/agent/cloudinit/file_writer_test.go b/agent/cloudinit/file_writer_test.go index f1d8551e8..839b44e17 100644 --- a/agent/cloudinit/file_writer_test.go +++ b/agent/cloudinit/file_writer_test.go @@ -1,7 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package cloudinit +package cloudinit_test import ( "io/fs" @@ -12,6 +12,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" ) var _ = Describe("FileWriter", func() { @@ -32,21 +33,21 @@ var _ = Describe("FileWriter", func() { }) It("Should create a directory if it does not exists", func() { - err := FileWriter{}.MkdirIfNotExists(workDir) + err := cloudinit.FileWriter{}.MkdirIfNotExists(workDir) Expect(err).NotTo(HaveOccurred()) }) It("Should not create a directory if it already exists", func() { - err := FileWriter{}.MkdirIfNotExists(workDir) + err := cloudinit.FileWriter{}.MkdirIfNotExists(workDir) Expect(err).NotTo(HaveOccurred()) - err = FileWriter{}.MkdirIfNotExists(workDir) + err = cloudinit.FileWriter{}.MkdirIfNotExists(workDir) Expect(err).NotTo(HaveOccurred()) }) It("Should create and write to file", func() { filePermission := 0777 - file := Files{ + file := cloudinit.Files{ Path: path.Join(workDir, "file1.txt"), Encoding: "", Owner: "", @@ -55,13 +56,13 @@ var _ = Describe("FileWriter", func() { Append: false, } - err := FileWriter{}.MkdirIfNotExists(workDir) + err := cloudinit.FileWriter{}.MkdirIfNotExists(workDir) Expect(err).NotTo(HaveOccurred()) - err = FileWriter{}.WriteToFile(&file) + err = cloudinit.FileWriter{}.WriteToFile(&file) Expect(err).NotTo(HaveOccurred()) - buffer, err := ioutil.ReadFile(file.Path) + buffer, err := os.ReadFile(file.Path) Expect(err).NotTo(HaveOccurred()) Expect(string(buffer)).To(Equal(file.Content)) @@ -73,7 +74,7 @@ var _ = Describe("FileWriter", func() { It("Should append content to file when append mode is enabled", func() { fileOriginContent := "some-file-content-1" - file := Files{ + file := cloudinit.Files{ Path: path.Join(workDir, "file3.txt"), Encoding: "", Owner: "", @@ -82,16 +83,16 @@ var _ = Describe("FileWriter", func() { Append: true, } - err := FileWriter{}.MkdirIfNotExists(workDir) + err := cloudinit.FileWriter{}.MkdirIfNotExists(workDir) Expect(err).NotTo(HaveOccurred()) - err = ioutil.WriteFile(file.Path, []byte(fileOriginContent), 0644) + err = os.WriteFile(file.Path, []byte(fileOriginContent), 0644) Expect(err).NotTo(HaveOccurred()) - err = FileWriter{}.WriteToFile(&file) + err = cloudinit.FileWriter{}.WriteToFile(&file) Expect(err).NotTo(HaveOccurred()) - buffer, err := ioutil.ReadFile(file.Path) + buffer, err := os.ReadFile(file.Path) Expect(err).NotTo(HaveOccurred()) Expect(string(buffer)).To(Equal(fileOriginContent + file.Content)) diff --git a/agent/help_flag_test.go b/agent/help_flag_test.go index c68e329fe..7db66dd01 100644 --- a/agent/help_flag_test.go +++ b/agent/help_flag_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package main import ( diff --git a/agent/host_agent_suite_test.go b/agent/host_agent_suite_test.go index 624935bc0..86b5d0c26 100644 --- a/agent/host_agent_suite_test.go +++ b/agent/host_agent_suite_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package main import ( diff --git a/agent/host_agent_test.go b/agent/host_agent_test.go index 80b7d81b3..3e5aeb91b 100644 --- a/agent/host_agent_test.go +++ b/agent/host_agent_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package main import ( diff --git a/agent/installer/bundle_downloader_test.go b/agent/installer/bundle_downloader_test.go index d2de6eaab..eba030fdb 100644 --- a/agent/installer/bundle_downloader_test.go +++ b/agent/installer/bundle_downloader_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package installer import ( diff --git a/agent/installer/installer_suite_test.go b/agent/installer/installer_suite_test.go index 5f1025002..9e9d11ed4 100644 --- a/agent/installer/installer_suite_test.go +++ b/agent/installer/installer_suite_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package installer import ( diff --git a/agent/installer/installer_test.go b/agent/installer/installer_test.go index b68afeeee..59ba510ae 100644 --- a/agent/installer/installer_test.go +++ b/agent/installer/installer_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package installer import ( diff --git a/agent/installer/internal/algo/algo_suite_test.go b/agent/installer/internal/algo/algo_suite_test.go index 02c15b9fa..ce2fa75c3 100644 --- a/agent/installer/internal/algo/algo_suite_test.go +++ b/agent/installer/internal/algo/algo_suite_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package algo import ( diff --git a/agent/installer/internal/algo/algo_test.go b/agent/installer/internal/algo/algo_test.go index 0b4fb67b7..909b2235e 100644 --- a/agent/installer/internal/algo/algo_test.go +++ b/agent/installer/internal/algo/algo_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package algo import ( diff --git a/agent/installer/os_detector.go b/agent/installer/os_detector.go index 773332102..560830bf2 100644 --- a/agent/installer/os_detector.go +++ b/agent/installer/os_detector.go @@ -87,6 +87,7 @@ func (osd *osDetector) getHostnamectl() (string, error) { return string(out), nil } +// nolint: gocritic // Method that extracts the important information from getHostSystemInfo. func parseHostnamectl(systemInfo string) [3]string { const strIndicatingOSline string = "Operating System: " diff --git a/agent/installer/os_detector_test.go b/agent/installer/os_detector_test.go index 2a46379fe..cf8f83333 100644 --- a/agent/installer/os_detector_test.go +++ b/agent/installer/os_detector_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package installer import ( diff --git a/agent/installer/registry_test.go b/agent/installer/registry_test.go index dfd5c70b9..0241b00cb 100644 --- a/agent/installer/registry_test.go +++ b/agent/installer/registry_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package installer import ( diff --git a/agent/label_flag_test.go b/agent/label_flag_test.go index 0947b726f..40a2d1eb4 100644 --- a/agent/label_flag_test.go +++ b/agent/label_flag_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package main import ( diff --git a/apis/infrastructure/v1beta1/byocluster_webhook_test.go b/apis/infrastructure/v1beta1/byocluster_webhook_test.go index c25db3ad3..27fb148f1 100644 --- a/apis/infrastructure/v1beta1/byocluster_webhook_test.go +++ b/apis/infrastructure/v1beta1/byocluster_webhook_test.go @@ -1,13 +1,14 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package v1beta1 +package v1beta1_test import ( "context" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + byohv1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/kubectl/pkg/scheme" @@ -18,7 +19,7 @@ import ( var _ = Describe("ByoclusterWebhook", func() { Context("When ByoCluster gets a create request", func() { var ( - byoCluster *ByoCluster + byoCluster *byohv1beta1.ByoCluster ctx context.Context k8sClientUncached client.Client ) @@ -28,7 +29,7 @@ var _ = Describe("ByoclusterWebhook", func() { k8sClientUncached, clientErr = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(clientErr).NotTo(HaveOccurred()) - byoCluster = &ByoCluster{ + byoCluster = &byohv1beta1.ByoCluster{ TypeMeta: metav1.TypeMeta{ Kind: "ByoCluster", APIVersion: clusterv1.GroupVersion.String(), @@ -37,7 +38,7 @@ var _ = Describe("ByoclusterWebhook", func() { Name: "byocluster-create", Namespace: "default", }, - Spec: ByoClusterSpec{}, + Spec: byohv1beta1.ByoClusterSpec{}, } }) @@ -57,7 +58,7 @@ var _ = Describe("ByoclusterWebhook", func() { Context("When ByoCluster gets an update request", func() { var ( - byoCluster *ByoCluster + byoCluster *byohv1beta1.ByoCluster ctx context.Context k8sClientUncached client.Client ) @@ -67,7 +68,7 @@ var _ = Describe("ByoclusterWebhook", func() { k8sClientUncached, clientErr = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(clientErr).NotTo(HaveOccurred()) - byoCluster = &ByoCluster{ + byoCluster = &byohv1beta1.ByoCluster{ TypeMeta: metav1.TypeMeta{ Kind: "ByoCluster", APIVersion: clusterv1.GroupVersion.String(), @@ -76,7 +77,7 @@ var _ = Describe("ByoclusterWebhook", func() { Name: "byocluster-update", Namespace: "default", }, - Spec: ByoClusterSpec{ + Spec: byohv1beta1.ByoClusterSpec{ BundleLookupTag: "v0.1.0_alpha.2", }, } @@ -102,7 +103,7 @@ var _ = Describe("ByoclusterWebhook", func() { err := k8sClientUncached.Update(ctx, byoCluster) Expect(err).NotTo(HaveOccurred()) - updatedByoCluster := &ByoCluster{} + updatedByoCluster := &byohv1beta1.ByoCluster{} byoCLusterLookupKey := types.NamespacedName{Name: byoCluster.Name, Namespace: byoCluster.Namespace} Expect(k8sClientUncached.Get(ctx, byoCLusterLookupKey, updatedByoCluster)).Should(Not(HaveOccurred())) Expect(updatedByoCluster.Spec.BundleLookupTag).To(Equal(newBundleLookupTag)) diff --git a/apis/infrastructure/v1beta1/byohost_webhook_test.go b/apis/infrastructure/v1beta1/byohost_webhook_test.go index 3d0b91490..e47139f2d 100644 --- a/apis/infrastructure/v1beta1/byohost_webhook_test.go +++ b/apis/infrastructure/v1beta1/byohost_webhook_test.go @@ -1,13 +1,14 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package v1beta1 +package v1beta1_test import ( "context" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + byohv1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubectl/pkg/scheme" @@ -19,7 +20,7 @@ var _ = Describe("ByohostWebhook", func() { Context("When ByoHost gets a delete request", func() { var ( - byoHost *ByoHost + byoHost *byohv1beta1.ByoHost ctx context.Context k8sClientUncached client.Client ) @@ -30,7 +31,7 @@ var _ = Describe("ByohostWebhook", func() { k8sClientUncached, clientErr = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(clientErr).NotTo(HaveOccurred()) - byoHost = &ByoHost{ + byoHost = &byohv1beta1.ByoHost{ TypeMeta: metav1.TypeMeta{ Kind: "ByoHost", APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", @@ -39,7 +40,7 @@ var _ = Describe("ByohostWebhook", func() { GenerateName: "byohost-", Namespace: "default", }, - Spec: ByoHostSpec{}, + Spec: byohv1beta1.ByoHostSpec{}, } Expect(k8sClientUncached.Create(ctx, byoHost)).Should(Succeed()) }) @@ -51,10 +52,10 @@ var _ = Describe("ByohostWebhook", func() { Context("When ByoHost has MachineRef assigned", func() { var ( - byoMachine *ByoMachine + byoMachine *byohv1beta1.ByoMachine ) BeforeEach(func() { - byoMachine = &ByoMachine{ + byoMachine = &byohv1beta1.ByoMachine{ TypeMeta: metav1.TypeMeta{ Kind: "ByoMachine", APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", @@ -63,7 +64,7 @@ var _ = Describe("ByohostWebhook", func() { GenerateName: "byomachine-", Namespace: "default", }, - Spec: ByoMachineSpec{}, + Spec: byohv1beta1.ByoMachineSpec{}, } Expect(k8sClientUncached.Create(ctx, byoMachine)).Should(Succeed()) diff --git a/apis/infrastructure/v1beta1/webhook_suite_test.go b/apis/infrastructure/v1beta1/webhook_suite_test.go index 09b9623cd..66e2a58d8 100644 --- a/apis/infrastructure/v1beta1/webhook_suite_test.go +++ b/apis/infrastructure/v1beta1/webhook_suite_test.go @@ -1,7 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package v1beta1 +package v1beta1_test import ( "context" @@ -14,6 +14,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + byohv1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" admissionv1beta1 "k8s.io/api/admission/v1beta1" "k8s.io/kubectl/pkg/scheme" @@ -67,14 +68,14 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - err = AddToScheme(scheme.Scheme) + err = byohv1beta1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) err = admissionv1beta1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) - err = AddToScheme(scheme.Scheme) + err = byohv1beta1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) @@ -96,10 +97,10 @@ var _ = BeforeSuite(func() { }) Expect(err).NotTo(HaveOccurred()) - err = (&ByoHost{}).SetupWebhookWithManager(mgr) + err = (&byohv1beta1.ByoHost{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) - err = (&ByoCluster{}).SetupWebhookWithManager(mgr) + err = (&byohv1beta1.ByoCluster{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:webhook diff --git a/controllers/infrastructure/byomachine_controller.go b/controllers/infrastructure/byomachine_controller.go index 67b407f4b..ba8925a8f 100644 --- a/controllers/infrastructure/byomachine_controller.go +++ b/controllers/infrastructure/byomachine_controller.go @@ -40,7 +40,7 @@ import ( ) const ( - providerIDPrefix = "byoh://" + ProviderIDPrefix = "byoh://" providerIDSuffixLength = 6 RequeueForbyohost = 10 * time.Second ) @@ -260,7 +260,7 @@ func (r *ByoMachineReconciler) reconcileNormal(ctx context.Context, machineScope if machineScope.ByoMachine.Spec.ProviderID == "" { logger.Info("Updating Node with ProviderID") - providerID := fmt.Sprintf("%s%s/%s", providerIDPrefix, machineScope.ByoHost.Name, util.RandomString(providerIDSuffixLength)) + providerID := fmt.Sprintf("%s%s/%s", ProviderIDPrefix, machineScope.ByoHost.Name, util.RandomString(providerIDSuffixLength)) remoteClient, err := r.getRemoteClient(ctx, machineScope.ByoMachine) if err != nil { logger.Error(err, "failed to get remote client") diff --git a/controllers/infrastructure/byomachine_controller_test.go b/controllers/infrastructure/byomachine_controller_test.go index 145fcd618..348e8f380 100644 --- a/controllers/infrastructure/byomachine_controller_test.go +++ b/controllers/infrastructure/byomachine_controller_test.go @@ -1,7 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package controllers +package controllers_test import ( "context" @@ -11,6 +11,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + controllers "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/controllers/infrastructure" "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" eventutils "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/utils/events" corev1 "k8s.io/api/core/v1" @@ -170,7 +171,7 @@ var _ = Describe("Controllers/ByomachineController", func() { // assert ByoMachine does not exists deletedByoMachine := &infrastructurev1beta1.ByoMachine{} err = k8sClientUncached.Get(ctx, byoMachineLookupKey, deletedByoMachine) - Expect(err).To(MatchError(fmt.Sprintf("byomachines.infrastructure.cluster.x-k8s.io \"%s\" not found", byoMachineLookupKey.Name))) + Expect(err).To(MatchError(fmt.Sprintf("byomachines.infrastructure.cluster.x-k8s.io %q not found", byoMachineLookupKey.Name))) }) }) @@ -213,7 +214,7 @@ var _ = Describe("Controllers/ByomachineController", func() { createdByoMachine := &infrastructurev1beta1.ByoMachine{} err = k8sClientUncached.Get(ctx, byoMachineLookupKey, createdByoMachine) Expect(err).ToNot(HaveOccurred()) - Expect(createdByoMachine.Spec.ProviderID).To(ContainSubstring(providerIDPrefix)) + Expect(createdByoMachine.Spec.ProviderID).To(ContainSubstring(controllers.ProviderIDPrefix)) Expect(createdByoMachine.Status.Ready).To(BeTrue()) actualCondition := conditions.Get(createdByoMachine, infrastructurev1beta1.BYOHostReady) @@ -234,7 +235,7 @@ var _ = Describe("Controllers/ByomachineController", func() { err = clientFake.Get(ctx, types.NamespacedName{Name: byoHost.Name, Namespace: defaultNamespace}, &node) Expect(err).NotTo(HaveOccurred()) - Expect(node.Spec.ProviderID).To(ContainSubstring(providerIDPrefix)) + Expect(node.Spec.ProviderID).To(ContainSubstring(controllers.ProviderIDPrefix)) }) Context("When ByoMachine is attached to a host", func() { @@ -299,7 +300,7 @@ var _ = Describe("Controllers/ByomachineController", func() { // assert ByoMachine does not exists err = k8sClientUncached.Get(ctx, byoMachineLookupKey, deletedByoMachine) - Expect(err).To(MatchError(fmt.Sprintf("byomachines.infrastructure.cluster.x-k8s.io \"%s\" not found", byoMachineLookupKey.Name))) + Expect(err).To(MatchError(fmt.Sprintf("byomachines.infrastructure.cluster.x-k8s.io %q not found", byoMachineLookupKey.Name))) }) }) }) @@ -536,7 +537,7 @@ var _ = Describe("Controllers/ByomachineController", func() { Expect(err).NotTo(HaveOccurred()) var nodeTagged bool - if strings.Contains(node1.Spec.ProviderID, providerIDPrefix) || strings.Contains(node2.Spec.ProviderID, providerIDPrefix) { + if strings.Contains(node1.Spec.ProviderID, controllers.ProviderIDPrefix) || strings.Contains(node2.Spec.ProviderID, controllers.ProviderIDPrefix) { nodeTagged = true } Expect(nodeTagged).To(Equal(true)) @@ -580,7 +581,7 @@ var _ = Describe("Controllers/ByomachineController", func() { err = clientFake.Get(ctx, types.NamespacedName{Name: byoHost1.Name, Namespace: defaultNamespace}, &node) Expect(err).NotTo(HaveOccurred()) - Expect(node.Spec.ProviderID).To(ContainSubstring(providerIDPrefix)) + Expect(node.Spec.ProviderID).To(ContainSubstring(controllers.ProviderIDPrefix)) }) AfterEach(func() { diff --git a/controllers/infrastructure/suite_test.go b/controllers/infrastructure/suite_test.go index 25169b120..e189a582d 100644 --- a/controllers/infrastructure/suite_test.go +++ b/controllers/infrastructure/suite_test.go @@ -1,7 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package controllers +package controllers_test import ( "context" @@ -22,6 +22,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" + controllers "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/controllers/infrastructure" "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/test/builder" //+kubebuilder:scaffold:imports @@ -38,7 +39,7 @@ import ( var ( testEnv *envtest.Environment clientFake client.Client - reconciler *ByoMachineReconciler + reconciler *controllers.ByoMachineReconciler recorder *record.FakeRecorder byoCluster *infrastructurev1beta1.ByoCluster capiCluster *clusterv1.Cluster @@ -112,7 +113,7 @@ var _ = BeforeSuite(func() { ).Build() recorder = record.NewFakeRecorder(32) - reconciler = &ByoMachineReconciler{ + reconciler = &controllers.ByoMachineReconciler{ Client: k8sManager.GetClient(), Tracker: remote.NewTestClusterCacheTracker(logf.NullLogger{}, clientFake, scheme.Scheme, client.ObjectKey{Name: capiCluster.Name, Namespace: capiCluster.Namespace}), Recorder: recorder, diff --git a/test/e2e/byohost_reuse_test.go b/test/e2e/byohost_reuse_test.go index 4d4ac3e25..8b3ecb0c1 100644 --- a/test/e2e/byohost_reuse_test.go +++ b/test/e2e/byohost_reuse_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package e2e import ( diff --git a/test/e2e/e2e_debug_helper.go b/test/e2e/e2e_debug_helper.go index 29f9af68b..368f285a2 100644 --- a/test/e2e/e2e_debug_helper.go +++ b/test/e2e/e2e_debug_helper.go @@ -7,7 +7,6 @@ import ( "bufio" "fmt" "io/fs" - "io/ioutil" "os" "os/exec" @@ -69,7 +68,7 @@ func Showf(format string, a ...interface{}) { } func ShowFileContent(fileName string) { - content, err := ioutil.ReadFile(fileName) + content, err := os.ReadFile(fileName) if err != nil { Showf("ioutil.ReadFile %s return failed: Get err %v", fileName, err) return diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index fdc60c024..502543efb 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package e2e import ( diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index de3ff2a4e..60f2e7174 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package e2e import ( diff --git a/test/e2e/md_scale_test.go b/test/e2e/md_scale_test.go index ee1d6b331..da25336b0 100644 --- a/test/e2e/md_scale_test.go +++ b/test/e2e/md_scale_test.go @@ -1,6 +1,7 @@ // Copyright 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// nolint: testpackage package e2e import ( From dc57dbacac2c54bc416a89f93c07b1817be29305 Mon Sep 17 00:00:00 2001 From: Anusha Hegde Date: Tue, 18 Jan 2022 03:47:30 +0000 Subject: [PATCH 2/2] Remove unused nolint --- agent/installer/os_detector.go | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/installer/os_detector.go b/agent/installer/os_detector.go index 560830bf2..773332102 100644 --- a/agent/installer/os_detector.go +++ b/agent/installer/os_detector.go @@ -87,7 +87,6 @@ func (osd *osDetector) getHostnamectl() (string, error) { return string(out), nil } -// nolint: gocritic // Method that extracts the important information from getHostSystemInfo. func parseHostnamectl(systemInfo string) [3]string { const strIndicatingOSline string = "Operating System: "