@@ -21,7 +21,6 @@ import (
2121 "errors"
2222 "fmt"
2323 "reflect"
24- "strings"
2524 "testing"
2625 "time"
2726
@@ -569,7 +568,7 @@ func TestScheduleResourceBindingWithClusterAffinities(t *testing.T) {
569568 `{"metadata":{"annotations":{"policy.karmada.io/applied-placement":"{\"clusterAffinities\":[{\"affinityName\":\"affinity1\",\"clusterNames\":[\"cluster1\"]},{\"affinityName\":\"affinity2\",\"clusterNames\":[\"cluster2\"]}]}"}},"spec":{"clusters":[{"name":"cluster1","replicas":1}]}}` ,
570569 `{"status":{"schedulerObservingAffinityName":"affinity1"}}` ,
571570 },
572- expectedEvent : "Normal ScheduleBindingSucceed Binding has been scheduled successfully." ,
571+ expectedEvent : fmt . Sprintf ( "Normal ScheduleBindingSucceed %s Result: {cluster1:1}" , successfulSchedulingMessage ) ,
573572 },
574573 {
575574 name : "successful scheduling with second affinity" ,
@@ -688,11 +687,7 @@ func TestScheduleResourceBindingWithClusterAffinities(t *testing.T) {
688687 // Check if an event was recorded
689688 select {
690689 case event := <- fakeRecorder .Events :
691- if strings .Contains (event , "ScheduleBindingFailed" ) {
692- assert .Contains (t , event , tt .expectedEvent , "Event does not match expected" )
693- } else {
694- assert .Contains (t , event , "ScheduleBindingSucceed" , "Expected ScheduleBindingSucceed event" )
695- }
690+ assert .Contains (t , event , tt .expectedEvent , "Event does not match expected" )
696691 default :
697692 t .Errorf ("Expected an event to be recorded" )
698693 }
@@ -900,6 +895,7 @@ func TestScheduleClusterResourceBindingWithClusterAffinities(t *testing.T) {
900895 scheduleResults []core.ScheduleResult
901896 scheduleErrors []error
902897 expectError bool
898+ expectedEvent string
903899 }{
904900 {
905901 name : "successful scheduling with first affinity" ,
@@ -935,6 +931,7 @@ func TestScheduleClusterResourceBindingWithClusterAffinities(t *testing.T) {
935931 },
936932 scheduleErrors : []error {nil },
937933 expectError : false ,
934+ expectedEvent : fmt .Sprintf ("Normal ScheduleBindingSucceed %s Result {cluster1:1}" , successfulSchedulingMessage ),
938935 },
939936 {
940937 name : "successful scheduling with second affinity" ,
@@ -971,6 +968,7 @@ func TestScheduleClusterResourceBindingWithClusterAffinities(t *testing.T) {
971968 },
972969 scheduleErrors : []error {errors .New ("first affinity failed" ), nil },
973970 expectError : false ,
971+ expectedEvent : "Warning ScheduleBindingFailed failed to schedule ClusterResourceBinding(test-cluster-binding-2) with clusterAffiliates index(0): first affinity failed" ,
974972 },
975973 {
976974 name : "all affinities fail" ,
@@ -1000,6 +998,7 @@ func TestScheduleClusterResourceBindingWithClusterAffinities(t *testing.T) {
1000998 scheduleResults : []core.ScheduleResult {{}, {}},
1001999 scheduleErrors : []error {errors .New ("first affinity failed" ), errors .New ("second affinity failed" )},
10021000 expectError : true ,
1001+ expectedEvent : "Warning ScheduleBindingFailed failed to schedule ClusterResourceBinding(test-cluster-binding-fail) with clusterAffiliates index(0): first affinity failed" ,
10031002 },
10041003 }
10051004
@@ -1027,6 +1026,14 @@ func TestScheduleClusterResourceBindingWithClusterAffinities(t *testing.T) {
10271026 if (err != nil ) != tt .expectError {
10281027 t .Errorf ("scheduleClusterResourceBindingWithClusterAffinities() error = %v, expectError %v" , err , tt .expectError )
10291028 }
1029+
1030+ // Check if an event was recorded
1031+ select {
1032+ case event := <- fakeRecorder .Events :
1033+ assert .Contains (t , event , tt .expectedEvent , "Event does not match expected" )
1034+ default :
1035+ t .Errorf ("Expected an event to be recorded" )
1036+ }
10301037 })
10311038 }
10321039}
0 commit comments