|
| 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 | + // Different name, same RV doesn't really make sense, but helps with testing the |
| 22 | + // updateStore impl which relies on the equality of RVs alone. |
| 23 | + modPool1SameRV = &v1alpha1.InferencePool{ |
| 24 | + Spec: v1alpha1.InferencePoolSpec{ |
| 25 | + Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"}, |
| 26 | + }, |
| 27 | + ObjectMeta: metav1.ObjectMeta{ |
| 28 | + Name: "test-pool-mod", |
| 29 | + ResourceVersion: "50", |
| 30 | + }, |
| 31 | + } |
| 32 | + modPool1DiffRV = &v1alpha1.InferencePool{ |
| 33 | + Spec: v1alpha1.InferencePoolSpec{ |
| 34 | + Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"}, |
| 35 | + }, |
| 36 | + ObjectMeta: metav1.ObjectMeta{ |
| 37 | + Name: "test-pool-mod", |
| 38 | + ResourceVersion: "51", |
| 39 | + }, |
| 40 | + } |
| 41 | +) |
| 42 | + |
| 43 | +func TestUpdateDatastore_InferencePoolReconciler(t *testing.T) { |
| 44 | + tests := []struct { |
| 45 | + name string |
| 46 | + datastore *K8sDatastore |
| 47 | + incomingPool *v1alpha1.InferencePool |
| 48 | + wantPool *v1alpha1.InferencePool |
| 49 | + }{ |
| 50 | + { |
| 51 | + name: "InferencePool not set, should set InferencePool", |
| 52 | + datastore: &K8sDatastore{}, |
| 53 | + incomingPool: pool1.DeepCopy(), |
| 54 | + wantPool: pool1, |
| 55 | + }, |
| 56 | + { |
| 57 | + name: "InferencePool set, matching RVs, do nothing", |
| 58 | + datastore: &K8sDatastore{ |
| 59 | + inferencePool: pool1.DeepCopy(), |
| 60 | + }, |
| 61 | + incomingPool: modPool1SameRV.DeepCopy(), |
| 62 | + wantPool: pool1, |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "InferencePool set, differing RVs, re-set InferencePool", |
| 66 | + datastore: &K8sDatastore{ |
| 67 | + inferencePool: pool1.DeepCopy(), |
| 68 | + }, |
| 69 | + incomingPool: modPool1DiffRV.DeepCopy(), |
| 70 | + wantPool: modPool1DiffRV, |
| 71 | + }, |
| 72 | + } |
| 73 | + |
| 74 | + for _, test := range tests { |
| 75 | + t.Run(test.name, func(t *testing.T) { |
| 76 | + inferencePoolReconciler := &InferencePoolReconciler{Datastore: test.datastore} |
| 77 | + inferencePoolReconciler.updateDatastore(test.incomingPool) |
| 78 | + |
| 79 | + gotPool := inferencePoolReconciler.Datastore.inferencePool |
| 80 | + if !reflect.DeepEqual(gotPool, test.wantPool) { |
| 81 | + t.Errorf("Unexpected InferencePool: want %#v, got: %#v", test.wantPool, gotPool) |
| 82 | + } |
| 83 | + }) |
| 84 | + } |
| 85 | +} |
0 commit comments