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

Cleanup linter excludes #2218

Merged
merged 1 commit into from
Sep 17, 2024
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
10 changes: 0 additions & 10 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,3 @@ linters:
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude:
- "^redefines-builtin-id:"
- "^receiver-naming:"
- "unexported-return:"
- "context-as-argument:"
- "and that stutters"
- '`fixTestDeployment` - `namespace` always receives `"kyma-system"'
- "`fixCheckConfig` - `name` always receives `name`"
- "`fixCheckConfig` - `namespace` always receives `namespace`"
- "`fixTestHanaServiceBinding` - `namespace` always receives `namespace"
70 changes: 29 additions & 41 deletions internal/cmd/alpha/hana/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Hana is fully ready.
hanaNotInstalledMessage = `Checking Hana (test-namespace/test-name).
Hana is not fully ready.
`
testName = "test-name"
testNamespace = "test-namespace"
)

func Test_runCheck(t *testing.T) {
Expand Down Expand Up @@ -77,28 +79,24 @@ func Test_runCheck(t *testing.T) {
func Test_checkHanaInstance(t *testing.T) {
t.Run("ready", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHana := fixTestHanaServiceInstance(name, namespace, nil)
config := fixCheckConfig(name, namespace, testHana)
testHana := fixTestHanaServiceInstance(name, nil)
config := fixCheckConfig(testHana)
err := checkHanaInstance(&config)
require.Nil(t, err)
})

t.Run("not found", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHana := fixTestHanaServiceInstance("other-name", namespace, nil)
config := fixCheckConfig(name, namespace, testHana)
testHana := fixTestHanaServiceInstance("other-name", nil)
config := fixCheckConfig(testHana)
err := checkHanaInstance(&config)
require.NotNil(t, err)
errMsg := err.String()
require.Contains(t, errMsg, "serviceinstances.services.cloud.sap.com \"test-name\" not found")
})
t.Run("not ready", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHana := fixTestHanaServiceInstance(name, namespace, &map[string]interface{}{})
config := fixCheckConfig(name, namespace, testHana)
testHana := fixTestHanaServiceInstance(name, &map[string]interface{}{})
config := fixCheckConfig(testHana)
err := checkHanaInstance(&config)
require.NotNil(t, err)
errMsg := err.String()
Expand All @@ -109,27 +107,23 @@ func Test_checkHanaInstance(t *testing.T) {
func Test_checkHanaBinding(t *testing.T) {
t.Run("ready", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding(name, namespace, nil)
config := fixCheckConfig(name, namespace, testHanaBinding)
testHanaBinding := fixTestHanaServiceBinding(name, nil)
config := fixCheckConfig(testHanaBinding)
err := checkHanaBinding(&config)
require.Nil(t, err)
})
t.Run("not found", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding("other-name", namespace, nil)
config := fixCheckConfig(name, namespace, testHanaBinding)
testHanaBinding := fixTestHanaServiceBinding("other-name", nil)
config := fixCheckConfig(testHanaBinding)
err := checkHanaBinding(&config)
require.NotNil(t, err)
errMsg := err.String()
require.Contains(t, errMsg, "servicebindings.services.cloud.sap.com \"test-name\" not found")
})
t.Run("not ready", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding(name, namespace, &map[string]interface{}{})
config := fixCheckConfig(name, namespace, testHanaBinding)
testHanaBinding := fixTestHanaServiceBinding(name, &map[string]interface{}{})
config := fixCheckConfig(testHanaBinding)
err := checkHanaBinding(&config)
require.NotNil(t, err)
errMsg := err.String()
Expand All @@ -141,30 +135,24 @@ func Test_checkHanaBinding(t *testing.T) {

func Test_checkHanaBindingURL(t *testing.T) {
t.Run("ready", func(t *testing.T) {
name := "test-name"
urlName := name + "-url"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding(urlName, namespace, nil)
config := fixCheckConfig(name, namespace, testHanaBinding)
urlName := testName + "-url"
testHanaBinding := fixTestHanaServiceBinding(urlName, nil)
config := fixCheckConfig(testHanaBinding)
err := checkHanaBindingURL(&config)
require.Nil(t, err)
})
t.Run("not found", func(t *testing.T) {
name := "test-name"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding("other-name", namespace, nil)
config := fixCheckConfig(name, namespace, testHanaBinding)
testHanaBinding := fixTestHanaServiceBinding("other-name", nil)
config := fixCheckConfig(testHanaBinding)
err := checkHanaBindingURL(&config)
require.NotNil(t, err)
errMsg := err.String()
require.Contains(t, errMsg, "servicebindings.services.cloud.sap.com \"test-name-url\" not found")
})
t.Run("not ready", func(t *testing.T) {
name := "test-name"
urlName := name + "-url"
namespace := "test-namespace"
testHanaBinding := fixTestHanaServiceBinding(urlName, namespace, &map[string]interface{}{})
config := fixCheckConfig(name, namespace, testHanaBinding)
urlName := testName + "-url"
testHanaBinding := fixTestHanaServiceBinding(urlName, &map[string]interface{}{})
config := fixCheckConfig(testHanaBinding)
err := checkHanaBindingURL(&config)
require.NotNil(t, err)
errMsg := err.String()
Expand All @@ -174,7 +162,7 @@ func Test_checkHanaBindingURL(t *testing.T) {
})
}

func fixCheckConfig(name string, namespace string, objects ...runtime.Object) hanaCheckConfig {
func fixCheckConfig(objects ...runtime.Object) hanaCheckConfig {
scheme := runtime.NewScheme()
scheme.AddKnownTypes(btp.GVRServiceInstance.GroupVersion())
dynamic := dynamic_fake.NewSimpleDynamicClient(scheme, objects...)
Expand All @@ -186,19 +174,19 @@ func fixCheckConfig(name string, namespace string, objects ...runtime.Object) ha
TestBtpInterface: btp.NewClient(dynamic),
},
},
name: name,
namespace: namespace,
name: testName,
namespace: testNamespace,
timeout: 0,
}
return config
}

func fixTestHanaServiceInstance(name, namespace string, status *map[string]interface{}) *unstructured.Unstructured {
return fixTestHanaService("ServiceInstance", name, namespace, status)
func fixTestHanaServiceInstance(name string, status *map[string]interface{}) *unstructured.Unstructured {
return fixTestHanaService("ServiceInstance", name, testNamespace, status)
}

func fixTestHanaServiceBinding(name, namespace string, status *map[string]interface{}) *unstructured.Unstructured {
return fixTestHanaService("ServiceBinding", name, namespace, status)
func fixTestHanaServiceBinding(name string, status *map[string]interface{}) *unstructured.Unstructured {
return fixTestHanaService("ServiceBinding", name, testNamespace, status)
}

func fixTestHanaService(kind, name, namespace string, status *map[string]interface{}) *unstructured.Unstructured {
Expand Down
18 changes: 11 additions & 7 deletions internal/communitymodules/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
k8s_fake "k8s.io/client-go/kubernetes/fake"
)

const (
kymaNamespace = "kyma-system"
)

func Test_modulesCatalog(t *testing.T) {
t.Run("ok", func(t *testing.T) {
expectedResult := moduleMap{
Expand Down Expand Up @@ -176,9 +180,9 @@ func Test_installedModules(t *testing.T) {
defer httpServer.Close()

staticClient := k8s_fake.NewSimpleClientset(
fixTestDeployment("module1-controller-manager", "kyma-system", "1.7.0"),
fixTestDeployment("module2-manager", "kyma-system", "6.7.8"), // outdated
fixTestDeployment("other-deployment", "kyma-system", "1.2.3"))
fixTestDeployment("module1-controller-manager", "1.7.0"),
fixTestDeployment("module2-manager", "6.7.8"), // outdated
fixTestDeployment("other-deployment", "1.2.3"))
kubeClient := &kube_fake.FakeKubeClient{
TestKubernetesInterface: staticClient,
TestDynamicInterface: nil,
Expand Down Expand Up @@ -211,8 +215,8 @@ func Test_installedModules(t *testing.T) {
defer httpServer.Close()

staticClient := k8s_fake.NewSimpleClientset(
fixTestDeployment("module2-manager", "kyma-system", "4.5.6"),
fixTestDeployment("other-deployment", "kyma-system", "1.2.3"))
fixTestDeployment("module2-manager", "4.5.6"),
fixTestDeployment("other-deployment", "1.2.3"))
kubeClient := &kube_fake.FakeKubeClient{
TestKubernetesInterface: staticClient,
TestDynamicInterface: nil,
Expand Down Expand Up @@ -274,11 +278,11 @@ func fixTestKyma() *unstructured.Unstructured {
return u
}

func fixTestDeployment(name, namespace, imageTag string) *v1.Deployment {
func fixTestDeployment(name, imageTag string) *v1.Deployment {
return &v1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Namespace: kymaNamespace,
},
Spec: v1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Expand Down