|
| 1 | +package backend |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "inference.networking.x-k8s.io/gateway-api-inference-extension/api/v1alpha1" |
| 8 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 9 | +) |
| 10 | + |
| 11 | +var ( |
| 12 | + pool1 = &v1alpha1.InferencePool{ |
| 13 | + Spec: v1alpha1.InferencePoolSpec{ |
| 14 | + Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"}, |
| 15 | + }, |
| 16 | + ObjectMeta: metav1.ObjectMeta{ |
| 17 | + Name: "test-pool", |
| 18 | + ResourceVersion: "50", |
| 19 | + }, |
| 20 | + } |
| 21 | + modPool1SameRV = &v1alpha1.InferencePool{ |
| 22 | + Spec: v1alpha1.InferencePoolSpec{ |
| 23 | + Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"}, |
| 24 | + }, |
| 25 | + ObjectMeta: metav1.ObjectMeta{ |
| 26 | + Name: "test-pool-mod", |
| 27 | + ResourceVersion: "50", |
| 28 | + }, |
| 29 | + } |
| 30 | + modPool1DiffRV = &v1alpha1.InferencePool{ |
| 31 | + Spec: v1alpha1.InferencePoolSpec{ |
| 32 | + Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"}, |
| 33 | + }, |
| 34 | + ObjectMeta: metav1.ObjectMeta{ |
| 35 | + Name: "test-pool-mod", |
| 36 | + ResourceVersion: "51", |
| 37 | + }, |
| 38 | + } |
| 39 | +) |
| 40 | + |
| 41 | +func TestUpdateDatastore_InferencePoolReconciler(t *testing.T) { |
| 42 | + tests := []struct { |
| 43 | + name string |
| 44 | + datastore *K8sDatastore |
| 45 | + incomingPool *v1alpha1.InferencePool |
| 46 | + wantPool *v1alpha1.InferencePool |
| 47 | + }{ |
| 48 | + { |
| 49 | + name: "InferencePool not set, should set InferencePool", |
| 50 | + datastore: &K8sDatastore{}, |
| 51 | + incomingPool: pool1.DeepCopy(), |
| 52 | + wantPool: pool1, |
| 53 | + }, |
| 54 | + { |
| 55 | + name: "InferencePool set, matching RVs, do nothing", |
| 56 | + datastore: &K8sDatastore{ |
| 57 | + inferencePool: pool1.DeepCopy(), |
| 58 | + }, |
| 59 | + incomingPool: modPool1SameRV.DeepCopy(), |
| 60 | + wantPool: pool1, |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "InferencePool set, differing RVs, re-set InferencePool", |
| 64 | + datastore: &K8sDatastore{ |
| 65 | + inferencePool: pool1.DeepCopy(), |
| 66 | + }, |
| 67 | + incomingPool: modPool1DiffRV.DeepCopy(), |
| 68 | + wantPool: modPool1DiffRV, |
| 69 | + }, |
| 70 | + } |
| 71 | + |
| 72 | + for _, test := range tests { |
| 73 | + t.Run(test.name, func(t *testing.T) { |
| 74 | + inferencePoolReconciler := &InferencePoolReconciler{Datastore: test.datastore} |
| 75 | + inferencePoolReconciler.updateDatastore(test.incomingPool) |
| 76 | + |
| 77 | + expectedPool := inferencePoolReconciler.Datastore.inferencePool |
| 78 | + if !reflect.DeepEqual(expectedPool, test.wantPool) { |
| 79 | + t.Errorf("Unexpected InferencePool: want %#v, got: %#v", test.wantPool, expectedPool) |
| 80 | + } |
| 81 | + }) |
| 82 | + } |
| 83 | +} |
0 commit comments