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

Enable testpackage linter #326

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ linters:
- staticcheck
- structcheck
- stylecheck
- testpackage
- typecheck
- unconvert
# - unparam
Expand All @@ -59,7 +60,6 @@ linters:
# - lll
# - nestif
# - prealloc
# - testpackage
# - revive
# - scopelint
# - wsl
Expand Down
12 changes: 6 additions & 6 deletions agent/cloudinit/cloudinit_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand All @@ -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:
Expand All @@ -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))

Expand All @@ -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))
})
Expand All @@ -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))
})
Expand All @@ -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))
})
Expand Down
27 changes: 14 additions & 13 deletions agent/cloudinit/file_writer_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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() {
Expand All @@ -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: "",
Expand All @@ -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))

Expand All @@ -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: "",
Expand All @@ -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))

Expand Down
1 change: 1 addition & 0 deletions agent/help_flag_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package main

import (
Expand Down
1 change: 1 addition & 0 deletions agent/host_agent_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package main

import (
Expand Down
1 change: 1 addition & 0 deletions agent/host_agent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package main

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/bundle_downloader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package installer

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/installer_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package installer

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/installer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package installer

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/internal/algo/algo_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package algo

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/internal/algo/algo_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package algo

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/os_detector_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package installer

import (
Expand Down
1 change: 1 addition & 0 deletions agent/installer/registry_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package installer

import (
Expand Down
1 change: 1 addition & 0 deletions agent/label_flag_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// nolint: testpackage
package main

import (
Expand Down
17 changes: 9 additions & 8 deletions apis/infrastructure/v1beta1/byocluster_webhook_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
)
Expand All @@ -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(),
Expand All @@ -37,7 +38,7 @@ var _ = Describe("ByoclusterWebhook", func() {
Name: "byocluster-create",
Namespace: "default",
},
Spec: ByoClusterSpec{},
Spec: byohv1beta1.ByoClusterSpec{},
}
})

Expand All @@ -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
)
Expand All @@ -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(),
Expand All @@ -76,7 +77,7 @@ var _ = Describe("ByoclusterWebhook", func() {
Name: "byocluster-update",
Namespace: "default",
},
Spec: ByoClusterSpec{
Spec: byohv1beta1.ByoClusterSpec{
BundleLookupTag: "v0.1.0_alpha.2",
},
}
Expand All @@ -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))
Expand Down
15 changes: 8 additions & 7 deletions apis/infrastructure/v1beta1/byohost_webhook_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
)
Expand All @@ -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",
Expand All @@ -39,7 +40,7 @@ var _ = Describe("ByohostWebhook", func() {
GenerateName: "byohost-",
Namespace: "default",
},
Spec: ByoHostSpec{},
Spec: byohv1beta1.ByoHostSpec{},
}
Expect(k8sClientUncached.Create(ctx, byoHost)).Should(Succeed())
})
Expand All @@ -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",
Expand All @@ -63,7 +64,7 @@ var _ = Describe("ByohostWebhook", func() {
GenerateName: "byomachine-",
Namespace: "default",
},
Spec: ByoMachineSpec{},
Spec: byohv1beta1.ByoMachineSpec{},
}
Expect(k8sClientUncached.Create(ctx, byoMachine)).Should(Succeed())

Expand Down
Loading