From e3932d3357197b02463aa766ff0344a29008dc35 Mon Sep 17 00:00:00 2001 From: Kanika Rana Date: Wed, 7 Aug 2024 11:00:37 -0400 Subject: [PATCH] lint check --- .../toolchaincluster/healthchecker_test.go | 3 +-- .../toolchaincluster_controller_test.go | 22 +++++++++---------- pkg/test/client.go | 2 +- pkg/test/client_test.go | 5 ++++- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/controllers/toolchaincluster/healthchecker_test.go b/controllers/toolchaincluster/healthchecker_test.go index 8da6e932..5548465e 100644 --- a/controllers/toolchaincluster/healthchecker_test.go +++ b/controllers/toolchaincluster/healthchecker_test.go @@ -5,7 +5,6 @@ import ( "fmt" "testing" - toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/cluster" "github.com/codeready-toolchain/toolchain-common/pkg/test" "github.com/stretchr/testify/require" @@ -59,7 +58,7 @@ func TestClusterHealthChecks(t *testing.T) { for k, tc := range tests { t.Run(k, func(t *testing.T) { //given - tcType, sec := newToolchainCluster(tc.tcType, tcNs, tc.apiEndPoint, toolchainv1alpha1.ToolchainClusterStatus{}) + tcType, sec := newToolchainCluster(tc.tcType, tcNs, tc.apiEndPoint) cl := test.NewFakeClient(t, tcType, sec) reset := setupCachedClusters(t, cl, tcType) defer reset() diff --git a/controllers/toolchaincluster/toolchaincluster_controller_test.go b/controllers/toolchaincluster/toolchaincluster_controller_test.go index b4410b22..8acb316e 100644 --- a/controllers/toolchaincluster/toolchaincluster_controller_test.go +++ b/controllers/toolchaincluster/toolchaincluster_controller_test.go @@ -49,7 +49,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("ToolchainCluster not found", func(t *testing.T) { // given - NotFound, sec := newToolchainCluster("notfound", tcNs, "http://not-found.com", toolchainv1alpha1.ToolchainClusterStatus{}) + NotFound, sec := newToolchainCluster("notfound", tcNs, "http://not-found.com") cl := test.NewFakeClient(t, sec) reset := setupCachedClusters(t, cl, NotFound) @@ -66,7 +66,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("Error while getting ToolchainCluster", func(t *testing.T) { // given - tc, sec := newToolchainCluster("tc", tcNs, "http://tc.com", toolchainv1alpha1.ToolchainClusterStatus{}) + tc, sec := newToolchainCluster("tc", tcNs, "http://tc.com") cl := test.NewFakeClient(t, sec) cl.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error { @@ -87,7 +87,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("reconcile successful and requeued", func(t *testing.T) { // given - stable, sec := newToolchainCluster("stable", tcNs, "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + stable, sec := newToolchainCluster("stable", tcNs, "http://cluster.com") cl := test.NewFakeClient(t, stable, sec) reset := setupCachedClusters(t, cl, stable) @@ -106,7 +106,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("toolchain cluster cache not found", func(t *testing.T) { // given - unstable, _ := newToolchainCluster("unstable", tcNs, "http://unstable.com", toolchainv1alpha1.ToolchainClusterStatus{}) + unstable, _ := newToolchainCluster("unstable", tcNs, "http://unstable.com") cl := test.NewFakeClient(t, unstable) controller, req := prepareReconcile(unstable, cl, requeAfter) @@ -121,7 +121,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("error while updating a toolchain cluster status on cache not found", func(t *testing.T) { // given - stable, _ := newToolchainCluster("stable", tcNs, "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + stable, _ := newToolchainCluster("stable", tcNs, "http://cluster.com") cl := test.NewFakeClient(t, stable) cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error { @@ -141,7 +141,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("error while updating a toolchain cluster status when health-check failed", func(t *testing.T) { // given - stable, sec := newToolchainCluster("stable", tcNs, "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + stable, sec := newToolchainCluster("stable", tcNs, "http://cluster.com") expectedErr := fmt.Errorf("my test error") cl := test.NewFakeClient(t, stable, sec) cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error { @@ -165,7 +165,7 @@ func TestClusterControllerChecks(t *testing.T) { t.Run("migrates connection settings to kubeconfig in secret", func(t *testing.T) { // given - tc, secret := newToolchainCluster("tc", tcNs, "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + tc, secret := newToolchainCluster("tc", tcNs, "http://cluster.com") cl := test.NewFakeClient(t, tc, secret) reset := setupCachedClusters(t, cl, tc) defer reset() @@ -201,7 +201,7 @@ func TestClusterControllerChecks(t *testing.T) { func TestGetClusterHealth(t *testing.T) { t.Run("Check health default", func(t *testing.T) { // given - stable, sec := newToolchainCluster("stable", "test-namespace", "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + stable, sec := newToolchainCluster("stable", "test-namespace", "http://cluster.com") cl := test.NewFakeClient(t, stable, sec) reset := setupCachedClusters(t, cl, stable) @@ -222,7 +222,7 @@ func TestGetClusterHealth(t *testing.T) { }) t.Run("get health condition when health obtained is false ", func(t *testing.T) { // given - stable, sec := newToolchainCluster("stable", "test-namespace", "http://cluster.com", toolchainv1alpha1.ToolchainClusterStatus{}) + stable, sec := newToolchainCluster("stable", "test-namespace", "http://cluster.com") cl := test.NewFakeClient(t, stable, sec) reset := setupCachedClusters(t, cl, stable) @@ -275,8 +275,8 @@ func setupCachedClusters(t *testing.T, cl *test.FakeClient, clusters ...*toolcha } } -func newToolchainCluster(name, tcNs string, apiEndpoint string, status toolchainv1alpha1.ToolchainClusterStatus) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret) { - toolchainCluster, secret := test.NewToolchainClusterWithEndpoint(name, tcNs, "secret", apiEndpoint, status, map[string]string{"namespace": "test-namespace"}) +func newToolchainCluster(name, tcNs, apiEndpoint string) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret) { + toolchainCluster, secret := test.NewToolchainClusterWithEndpoint(name, tcNs, "secret", apiEndpoint, toolchainv1alpha1.ToolchainClusterStatus{}, map[string]string{"namespace": "test-namespace"}) return toolchainCluster, secret } diff --git a/pkg/test/client.go b/pkg/test/client.go index c509d753..ef3d3be9 100644 --- a/pkg/test/client.go +++ b/pkg/test/client.go @@ -196,7 +196,7 @@ func getAllToolchainResources(s *runtime.Scheme) []client.Object { toolchainObjs := make([]client.Object, 0) KindToTypeMap := s.KnownTypes(toolchainv1alpha1.GroupVersion) var kinds []string - for key, _ := range KindToTypeMap { + for key := range KindToTypeMap { kinds = append(kinds, key) } for _, k := range kinds { diff --git a/pkg/test/client_test.go b/pkg/test/client_test.go index 479606bf..d98154e5 100644 --- a/pkg/test/client_test.go +++ b/pkg/test/client_test.go @@ -126,7 +126,10 @@ func TestNewClient(t *testing.T) { t.Run("status update fails when the objects being updated doesn't have status", func(t *testing.T) { created, _ := createAndGetSecret(t, fclient) - require.Error(t, fclient.Status().Update(context.TODO(), created)) + err := fclient.Status().Update(context.TODO(), created) + require.Error(t, err) + errString := "secrets \"" + created.Name + "\" not found" + require.EqualError(t, err, errString) }) t.Run("patch", func(t *testing.T) {