forked from kubernetes-sigs/gateway-api-inference-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinferencepool_reconciler_test.go
85 lines (79 loc) · 2.29 KB
/
inferencepool_reconciler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package backend
import (
"reflect"
"testing"
"inference.networking.x-k8s.io/gateway-api-inference-extension/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
pool1 = &v1alpha1.InferencePool{
Spec: v1alpha1.InferencePoolSpec{
Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"},
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pool",
ResourceVersion: "50",
},
}
// Different name, same RV doesn't really make sense, but helps with testing the
// updateStore impl which relies on the equality of RVs alone.
modPool1SameRV = &v1alpha1.InferencePool{
Spec: v1alpha1.InferencePoolSpec{
Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"},
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pool-mod",
ResourceVersion: "50",
},
}
modPool1DiffRV = &v1alpha1.InferencePool{
Spec: v1alpha1.InferencePoolSpec{
Selector: map[v1alpha1.LabelKey]v1alpha1.LabelValue{"app": "vllm"},
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pool-mod",
ResourceVersion: "51",
},
}
)
func TestUpdateDatastore_InferencePoolReconciler(t *testing.T) {
tests := []struct {
name string
datastore *K8sDatastore
incomingPool *v1alpha1.InferencePool
wantPool *v1alpha1.InferencePool
}{
{
name: "InferencePool not set, should set InferencePool",
datastore: &K8sDatastore{},
incomingPool: pool1.DeepCopy(),
wantPool: pool1,
},
{
name: "InferencePool set, matching RVs, do nothing",
datastore: &K8sDatastore{
inferencePool: pool1.DeepCopy(),
},
incomingPool: modPool1SameRV.DeepCopy(),
wantPool: pool1,
},
{
name: "InferencePool set, differing RVs, re-set InferencePool",
datastore: &K8sDatastore{
inferencePool: pool1.DeepCopy(),
},
incomingPool: modPool1DiffRV.DeepCopy(),
wantPool: modPool1DiffRV,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
inferencePoolReconciler := &InferencePoolReconciler{Datastore: test.datastore}
inferencePoolReconciler.updateDatastore(test.incomingPool)
gotPool := inferencePoolReconciler.Datastore.inferencePool
if !reflect.DeepEqual(gotPool, test.wantPool) {
t.Errorf("Unexpected InferencePool: want %#v, got: %#v", test.wantPool, gotPool)
}
})
}
}