Skip to content

Commit

Permalink
tests: migrate nrt tests to ctrl runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpaper committed Nov 1, 2023
1 parent b1354b9 commit c3ee7ed
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 94 deletions.
23 changes: 14 additions & 9 deletions pkg/noderesourcetopology/cache/discardreserved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ limitations under the License.
package cache

import (
"context"
"reflect"
"testing"

topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
faketopologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/clientset/versioned/fake"
topologyinformers "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/informers/externalversions"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

tu "sigs.k8s.io/scheduler-plugins/test/util"
)

func TestDiscardReservedNodesGetNRTCopy(t *testing.T) {
fakeClient := faketopologyv1alpha2.NewSimpleClientset()
fakeInformer := topologyinformers.NewSharedInformerFactory(fakeClient, 0).Topology().V1alpha2().NodeResourceTopologies()
fakeClient, err := tu.NewFakeClient()
if err != nil {
t.Fatal(err)
}

nrtCache := NewDiscardReserved(fakeInformer.Lister())
ctx := context.Background()
nrtCache := NewDiscardReserved(fakeClient)
var nrtObj *topologyv1alpha2.NodeResourceTopology
nrtObj, _ = nrtCache.GetCachedNRTCopy("node1", &corev1.Pod{})
nrtObj, _ = nrtCache.GetCachedNRTCopy(ctx, "node1", &corev1.Pod{})
if nrtObj != nil {
t.Fatalf("non-empty object from empty cache")
}
Expand Down Expand Up @@ -66,10 +71,10 @@ func TestDiscardReservedNodesGetNRTCopy(t *testing.T) {
},
}
for _, obj := range nodeTopologies {
fakeInformer.Informer().GetStore().Update(obj)
fakeClient.Update(ctx, obj)
}

nrtObj, ok := nrtCache.GetCachedNRTCopy("node1", &corev1.Pod{})
nrtObj, ok := nrtCache.GetCachedNRTCopy(ctx, "node1", &corev1.Pod{})
if !reflect.DeepEqual(nrtObj, nodeTopologies[0]) {
t.Fatalf("unexpected object from cache\ngot: %s\nexpected: %s\n", dumpNRT(nrtObj), dumpNRT(nodeTopologies[0]))
}
Expand All @@ -88,7 +93,7 @@ func TestDiscardReservedNodesGetNRTCopyFails(t *testing.T) {
},
}

nrtObj, ok := nrtCache.GetCachedNRTCopy("node1", &corev1.Pod{})
nrtObj, ok := nrtCache.GetCachedNRTCopy(context.Background(), "node1", &corev1.Pod{})
if ok {
t.Fatal("expected false\ngot true\n")
}
Expand Down
Loading

0 comments on commit c3ee7ed

Please sign in to comment.