Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Aug 15, 2024
1 parent cb2886a commit f83583a
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/record"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
karmadafake "github.com/karmada-io/karmada/pkg/generated/clientset/versioned/fake"
"github.com/karmada-io/karmada/pkg/util"
Expand Down Expand Up @@ -162,78 +161,6 @@ func TestCreateScheduler(t *testing.T) {
})
}
}

func TestReconcileEstimatorConnection(t *testing.T) {
dynamicClient := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme())
karmadaClient := karmadafake.NewSimpleClientset()
kubeClient := fake.NewSimpleClientset()
scheduler, err := NewScheduler(dynamicClient, karmadaClient, kubeClient, WithEnableSchedulerEstimator(true))
if err != nil {
t.Fatalf("Failed to create scheduler: %v", err)
}

clusterName := "test-cluster"
cluster := &clusterv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{Name: clusterName},
Spec: clusterv1alpha1.ClusterSpec{SyncMode: clusterv1alpha1.Pull},
}
_, err = karmadaClient.ClusterV1alpha1().Clusters().Create(context.TODO(), cluster, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create cluster: %v", err)
}

tests := []struct {
name string
key util.QueueKey
disableSchedulerEstimatorInPullMode bool
expectedError bool
expectEstablishConnection bool
}{
{
name: "Invalid key",
key: 123,
expectedError: true,
},
{
name: "Cluster not found",
key: "non-existent-cluster",
expectedError: false,
},
{
name: "Cluster in pull mode, estimator disabled",
key: clusterName,
disableSchedulerEstimatorInPullMode: true,
expectedError: false,
expectEstablishConnection: false,
},
{
name: "Cluster in pull mode, estimator enabled",
key: clusterName,
disableSchedulerEstimatorInPullMode: false,
expectedError: false,
expectEstablishConnection: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
scheduler.disableSchedulerEstimatorInPullMode = tt.disableSchedulerEstimatorInPullMode

err := scheduler.reconcileEstimatorConnection(tt.key)
if (err != nil) != tt.expectedError {
t.Errorf("reconcileEstimatorConnection() error = %v, expectedError %v", err, tt.expectedError)
}

// We can't directly assert whether EstablishConnection is called.
// Instead, we'll check for conditions around its invocation.
// If EstablishConnection should be called, the error should be nil, and no early returns should have occurred.
if tt.expectEstablishConnection && err != nil {
t.Errorf("Expected EstablishConnection to be called, but got error: %v", err)
}
})
}
}

func Test_patchBindingStatusCondition(t *testing.T) {
oneHourBefore := time.Now().Add(-1 * time.Hour).Round(time.Second)
oneHourAfter := time.Now().Add(1 * time.Hour).Round(time.Second)
Expand Down

0 comments on commit f83583a

Please sign in to comment.