Skip to content

Commit

Permalink
lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
ranakan19 committed Aug 7, 2024
1 parent 631693e commit e3932d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
3 changes: 1 addition & 2 deletions controllers/toolchaincluster/healthchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 11 additions & 11 deletions controllers/toolchaincluster/toolchaincluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/test/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/test/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e3932d3

Please sign in to comment.