MCPcopy
hub / github.com/microsoft/retina / TestAddPodSvcNodeSameIP

Function TestAddPodSvcNodeSameIP

pkg/controllers/cache/cache_test.go:184–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestAddPodSvcNodeSameIP(t *testing.T) {
185 log.SetupZapLogger(log.GetDefaultLogOpts())
186 ctrl := gomock.NewController(t)
187 defer ctrl.Finish()
188 p := pubsub.NewMockPubSubInterface(ctrl)
189 var wg sync.WaitGroup
190 wg.Add(5) // 2 pod + 2 svc + 1 node publishes
191 doFn := func(pubsub.PubSubTopic, interface{}) { wg.Done() }
192 p.EXPECT().Publish(common.PubSubPods, gomock.Any()).Times(2).Do(doFn)
193 p.EXPECT().Publish(common.PubSubSvc, gomock.Any()).Times(2).Do(doFn)
194 p.EXPECT().Publish(common.PubSubNode, gomock.Any()).Times(1).Do(doFn)
195 p.EXPECT().Subscribe(common.PubSubAPIServer, gomock.Any()).Times(1)
196 c := New(p)
197 assert.NotNil(t, c)
198
199 addEndpoints := common.NewRetinaEndpoint("pod1", "ns1", nil)
200 addEndpoints.SetLabels(map[string]string{
201 "app": "app1",
202 })
203
204 addEndpoints.SetIPs(&common.IPAddresses{
205 IPv4: net.IPv4(1, 2, 3, 4),
206 })
207
208 err := c.UpdateRetinaEndpoint(addEndpoints)
209 assert.NoError(t, err)
210
211 addSvc := common.NewRetinaSvc("svc1", "ns1",
212 &common.IPAddresses{
213 IPv4: net.IPv4(1, 2, 3, 4),
214 }, nil, nil)
215
216 err = c.UpdateRetinaSvc(addSvc)
217 assert.NoError(t, err)
218
219 obj := c.GetObjByIP("1.2.3.4")
220 assert.NotNil(t, obj)
221 svc := obj.(*common.RetinaSvc)
222 assert.Equal(t, addSvc.Name(), svc.Name())
223 assert.Equal(t, addSvc.Namespace(), svc.Namespace())
224
225 addNode := common.NewRetinaNode("node1", net.IPv4(1, 2, 3, 4), "zone-1")
226
227 err = c.UpdateRetinaNode(addNode)
228 assert.NoError(t, err)
229
230 obj = c.GetObjByIP("1.2.3.4")
231 assert.NotNil(t, obj)
232 node := obj.(*common.RetinaNode)
233 assert.Equal(t, addNode.Name(), node.Name())
234 assert.Equal(t, addNode.IPString(), node.IPString())
235
236 wg.Wait()
237}
238
239func TestAddPodSvcNodeSameIPDiffNS(t *testing.T) {
240 log.SetupZapLogger(log.GetDefaultLogOpts())

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
SetLabelsMethod · 0.95
SetIPsMethod · 0.95
NameMethod · 0.95
IPStringMethod · 0.95
SetupZapLoggerFunction · 0.92
GetDefaultLogOptsFunction · 0.92
NewMockPubSubInterfaceFunction · 0.92
NewRetinaEndpointFunction · 0.92
NewRetinaSvcFunction · 0.92
NewRetinaNodeFunction · 0.92
DoMethod · 0.80

Tested by

no test coverage detected