@@ -21,7 +21,7 @@ import (
21
21
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
22
22
)
23
23
24
- // MockItemComparator provides a mock implementation of the `framework.ItemComparator` interface.
24
+ // MockItemComparator is a simple stub mock for the `framework.ItemComparator` interface.
25
25
type MockItemComparator struct {
26
26
FuncV framework.ItemComparatorFunc
27
27
ScoreTypeV string
@@ -30,12 +30,11 @@ type MockItemComparator struct {
30
30
func (m * MockItemComparator ) Func () framework.ItemComparatorFunc { return m .FuncV }
31
31
func (m * MockItemComparator ) ScoreType () string { return m .ScoreTypeV }
32
32
33
- var _ framework.ItemComparator = & MockItemComparator {}
34
-
35
- // MockFlowQueueAccessor is a mock implementation of the `framework.FlowQueueAccessor` interface .
33
+ // MockFlowQueueAccessor is a simple stub mock for the ` framework.FlowQueueAccessor` interface.
34
+ // It is used for tests that require static, predictable return values from a queue accessor.
35
+ // For complex, stateful queue behavior, use the mock in `contracts/mocks.MockManagedQueue` .
36
36
type MockFlowQueueAccessor struct {
37
37
NameV string
38
- CapabilitiesV []framework.QueueCapability
39
38
LenV int
40
39
ByteSizeV uint64
41
40
PeekHeadV types.QueueItemAccessor
@@ -44,12 +43,15 @@ type MockFlowQueueAccessor struct {
44
43
PeekTailErrV error
45
44
FlowSpecV types.FlowSpecification
46
45
ComparatorV framework.ItemComparator
46
+ CapabilitiesV []framework.QueueCapability
47
47
}
48
48
49
49
func (m * MockFlowQueueAccessor ) Name () string { return m .NameV }
50
- func (m * MockFlowQueueAccessor ) Capabilities () []framework.QueueCapability { return m .CapabilitiesV }
51
50
func (m * MockFlowQueueAccessor ) Len () int { return m .LenV }
52
51
func (m * MockFlowQueueAccessor ) ByteSize () uint64 { return m .ByteSizeV }
52
+ func (m * MockFlowQueueAccessor ) Comparator () framework.ItemComparator { return m .ComparatorV }
53
+ func (m * MockFlowQueueAccessor ) FlowSpec () types.FlowSpecification { return m .FlowSpecV }
54
+ func (m * MockFlowQueueAccessor ) Capabilities () []framework.QueueCapability { return m .CapabilitiesV }
53
55
54
56
func (m * MockFlowQueueAccessor ) PeekHead () (types.QueueItemAccessor , error ) {
55
57
return m .PeekHeadV , m .PeekHeadErrV
@@ -59,51 +61,47 @@ func (m *MockFlowQueueAccessor) PeekTail() (types.QueueItemAccessor, error) {
59
61
return m .PeekTailV , m .PeekTailErrV
60
62
}
61
63
62
- func (m * MockFlowQueueAccessor ) Comparator () framework.ItemComparator { return m .ComparatorV }
63
- func (m * MockFlowQueueAccessor ) FlowSpec () types.FlowSpecification { return m .FlowSpecV }
64
-
65
64
var _ framework.FlowQueueAccessor = & MockFlowQueueAccessor {}
66
65
67
- // MockPriorityBandAccessor is a mock implementation of the `framework.PriorityBandAccessor` interface.
66
+ // MockPriorityBandAccessor is a behavioral mock for the `framework.MockPriorityBandAccessor` interface.
67
+ // Simple accessors are configured with public value fields (e.g., `PriorityV`).
68
+ // Complex methods with logic are configured with function fields (e.g., `IterateQueuesFunc`).
68
69
type MockPriorityBandAccessor struct {
69
- PriorityV uint
70
- PriorityNameV string
71
- FlowIDsV []string
72
- QueueV framework.FlowQueueAccessor // Value to return for any Queue(flowID) call
73
- QueueFuncV func (flowID string ) framework.FlowQueueAccessor
74
- IterateQueuesV func (callback func (queue framework.FlowQueueAccessor ) bool )
70
+ PriorityV uint
71
+ PriorityNameV string
72
+ FlowIDsFunc func () []string
73
+ QueueFunc func (flowID string ) framework.FlowQueueAccessor
74
+ IterateQueuesFunc func (callback func (queue framework.FlowQueueAccessor ) (keepIterating bool ))
75
75
}
76
76
77
77
func (m * MockPriorityBandAccessor ) Priority () uint { return m .PriorityV }
78
78
func (m * MockPriorityBandAccessor ) PriorityName () string { return m .PriorityNameV }
79
- func (m * MockPriorityBandAccessor ) FlowIDs () []string { return m .FlowIDsV }
79
+
80
+ func (m * MockPriorityBandAccessor ) FlowIDs () []string {
81
+ if m .FlowIDsFunc != nil {
82
+ return m .FlowIDsFunc ()
83
+ }
84
+ return nil
85
+ }
80
86
81
87
func (m * MockPriorityBandAccessor ) Queue (flowID string ) framework.FlowQueueAccessor {
82
- if m .QueueFuncV != nil {
83
- return m .QueueFuncV (flowID )
88
+ if m .QueueFunc != nil {
89
+ return m .QueueFunc (flowID )
84
90
}
85
- return m . QueueV
91
+ return nil
86
92
}
87
93
88
94
func (m * MockPriorityBandAccessor ) IterateQueues (callback func (queue framework.FlowQueueAccessor ) bool ) {
89
- if m .IterateQueuesV != nil {
90
- m .IterateQueuesV (callback )
91
- } else {
92
- // Default behavior: iterate based on FlowIDsV and QueueV/QueueFuncV
93
- for _ , id := range m .FlowIDsV {
94
- q := m .Queue (id )
95
- if q != nil { // Only call callback if queue exists
96
- if ! callback (q ) {
97
- return
98
- }
99
- }
100
- }
95
+ if m .IterateQueuesFunc != nil {
96
+ m .IterateQueuesFunc (callback )
101
97
}
102
98
}
103
99
104
100
var _ framework.PriorityBandAccessor = & MockPriorityBandAccessor {}
105
101
106
- // MockSafeQueue is a mock implementation of the `framework.SafeQueue` interface.
102
+ // MockSafeQueue is a simple stub mock for the `framework.SafeQueue` interface.
103
+ // It is used for tests that need to control the exact return values of a queue's methods without simulating the queue's
104
+ // internal logic or state.
107
105
type MockSafeQueue struct {
108
106
NameV string
109
107
CapabilitiesV []framework.QueueCapability
@@ -162,24 +160,48 @@ func (m *MockSafeQueue) Drain() ([]types.QueueItemAccessor, error) {
162
160
163
161
var _ framework.SafeQueue = & MockSafeQueue {}
164
162
165
- // MockIntraFlowDispatchPolicy is a mock implementation of the `framework.IntraFlowDispatchPolicy` interface.
163
+ // MockIntraFlowDispatchPolicy is a behavioral mock for the `framework.IntraFlowDispatchPolicy` interface.
164
+ // Simple accessors are configured with public value fields (e.g., `NameV`).
165
+ // Complex methods with logic are configured with function fields (e.g., `SelectItemFunc`).
166
166
type MockIntraFlowDispatchPolicy struct {
167
167
NameV string
168
- SelectItemV types.QueueItemAccessor
169
- SelectItemErrV error
170
168
ComparatorV framework.ItemComparator
171
169
RequiredQueueCapabilitiesV []framework.QueueCapability
170
+ SelectItemFunc func (queue framework.FlowQueueAccessor ) (types.QueueItemAccessor , error )
172
171
}
173
172
174
173
func (m * MockIntraFlowDispatchPolicy ) Name () string { return m .NameV }
175
174
func (m * MockIntraFlowDispatchPolicy ) Comparator () framework.ItemComparator { return m .ComparatorV }
175
+ func (m * MockIntraFlowDispatchPolicy ) RequiredQueueCapabilities () []framework.QueueCapability {
176
+ return m .RequiredQueueCapabilitiesV
177
+ }
176
178
177
179
func (m * MockIntraFlowDispatchPolicy ) SelectItem (queue framework.FlowQueueAccessor ) (types.QueueItemAccessor , error ) {
178
- return m .SelectItemV , m .SelectItemErrV
180
+ if m .SelectItemFunc != nil {
181
+ return m .SelectItemFunc (queue )
182
+ }
183
+ return nil , nil
179
184
}
180
185
181
- func (m * MockIntraFlowDispatchPolicy ) RequiredQueueCapabilities () []framework.QueueCapability {
182
- return m .RequiredQueueCapabilitiesV
186
+ var _ framework.IntraFlowDispatchPolicy = & MockIntraFlowDispatchPolicy {}
187
+
188
+ // MockInterFlowDispatchPolicy is a behavioral mock for the `framework.InterFlowDispatchPolicy` interface.
189
+ // Simple accessors are configured with public value fields (e.g., `NameV`).
190
+ // Complex methods with logic are configured with function fields (e.g., `SelectQueueFunc`).
191
+ type MockInterFlowDispatchPolicy struct {
192
+ NameV string
193
+ SelectQueueFunc func (band framework.PriorityBandAccessor ) (framework.FlowQueueAccessor , error )
183
194
}
184
195
185
- var _ framework.IntraFlowDispatchPolicy = & MockIntraFlowDispatchPolicy {}
196
+ func (m * MockInterFlowDispatchPolicy ) Name () string {
197
+ return m .NameV
198
+ }
199
+
200
+ func (m * MockInterFlowDispatchPolicy ) SelectQueue (band framework.PriorityBandAccessor ) (framework.FlowQueueAccessor , error ) {
201
+ if m .SelectQueueFunc != nil {
202
+ return m .SelectQueueFunc (band )
203
+ }
204
+ return nil , nil
205
+ }
206
+
207
+ var _ framework.InterFlowDispatchPolicy = & MockInterFlowDispatchPolicy {}
0 commit comments