Merge pull request #5998 from XiShanYongYe-Chang/flake-test-GetWorksByBindingID

fix flake test with GetWorksByBindingID func
This commit is contained in:
karmada-bot 2024-12-31 14:13:31 +08:00 committed by GitHub
commit ba1e68d22b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 21 deletions

View File

@ -309,17 +309,17 @@ func TestGetWorksByBindingID(t *testing.T) {
assert.NoError(t, workv1alpha1.Install(scheme))
bindingID := "test-binding-id"
work1 := &workv1alpha1.Work{
workWithRBID := &workv1alpha1.Work{
ObjectMeta: metav1.ObjectMeta{
Name: "work1",
Name: "workWithRBID",
Labels: map[string]string{
workv1alpha2.ResourceBindingPermanentIDLabel: bindingID,
},
},
}
work2 := &workv1alpha1.Work{
workWithCRBID := &workv1alpha1.Work{
ObjectMeta: metav1.ObjectMeta{
Name: "work2",
Name: "workWithCRBID",
Labels: map[string]string{
workv1alpha2.ClusterResourceBindingPermanentIDLabel: bindingID,
},
@ -330,33 +330,41 @@ func TestGetWorksByBindingID(t *testing.T) {
name string
works []client.Object
bindingID string
permanentIDKey string
namespaced bool
wantWorks []string
}{
{
name: "find namespaced binding works",
works: []client.Object{work1, work2},
works: []client.Object{workWithRBID, workWithCRBID},
bindingID: bindingID,
permanentIDKey: workv1alpha2.ResourceBindingPermanentIDLabel,
namespaced: true,
wantWorks: []string{"work1"},
wantWorks: []string{"workWithRBID"},
},
{
name: "find cluster binding works",
works: []client.Object{work1, work2},
works: []client.Object{workWithRBID, workWithCRBID},
bindingID: bindingID,
permanentIDKey: workv1alpha2.ClusterResourceBindingPermanentIDLabel,
namespaced: false,
wantWorks: []string{"work2"},
wantWorks: []string{"workWithCRBID"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := fake.NewClientBuilder().
fakeClient := fake.NewClientBuilder().
WithScheme(scheme).
WithIndex(
&workv1alpha1.Work{},
tt.permanentIDKey,
IndexerFuncBasedOnLabel(tt.permanentIDKey),
).
WithObjects(tt.works...).
Build()
workList, err := GetWorksByBindingID(context.TODO(), client, tt.bindingID, tt.namespaced)
workList, err := GetWorksByBindingID(context.TODO(), fakeClient, tt.bindingID, tt.namespaced)
assert.NoError(t, err)
assert.Equal(t, len(tt.wantWorks), len(workList.Items))