MCPcopy
hub / github.com/FairwindsOps/goldilocks / Test_listVPA

Function Test_listVPA

pkg/vpa/vpa_test.go:311–377  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

309}
310
311func Test_listVPA(t *testing.T) {
312 setupVPAForTests(t)
313 rec := GetInstance()
314
315 // test namespaces
316 testNS1 := nsTesting.DeepCopy()
317 testNS1.Name = "ns1"
318 testNS1.Namespace = "ns1"
319 testNS2 := nsTesting.DeepCopy()
320 testNS2.Name = "ns2"
321 testNS2.Namespace = "ns2"
322
323 controller1 := Controller{
324 APIVersion: "apps/v1",
325 Kind: "Deployment",
326 Name: "test1",
327 Unstructured: nil,
328 }
329 controller2 := Controller{
330 APIVersion: "apps/v1",
331 Kind: "Deployment",
332 Name: "test2",
333 Unstructured: nil,
334 }
335 controller3 := Controller{
336 APIVersion: "apps/v1",
337 Kind: "Deployment",
338 Name: "test3",
339 Unstructured: nil,
340 }
341 // test vpas
342 updateMode1, _ := vpaUpdateModeForResource(testNS1)
343 updateMode2, _ := vpaUpdateModeForResource(testNS2)
344 resourcePolicy1, _ := vpaResourcePolicyForResource(testNS1)
345 resourcePolicy2, _ := vpaResourcePolicyForResource(testNS2)
346 minReplicas1, _ := vpaMinReplicasForResource(testNS1)
347 minReplicas2, _ := vpaMinReplicasForResource(testNS2)
348
349 vpa1 := rec.getVPAObject(nil, testNS1, controller1, updateMode1, resourcePolicy1, minReplicas1)
350 vpa2 := rec.getVPAObject(nil, testNS1, controller2, updateMode1, resourcePolicy1, minReplicas1)
351 vpa3 := rec.getVPAObject(nil, testNS2, controller3, updateMode2, resourcePolicy2, minReplicas2)
352
353 // create vpas
354 _ = rec.createVPA(vpa1)
355 _ = rec.createVPA(vpa2)
356 _ = rec.createVPA(vpa3)
357
358 // list ns1
359 vpaList1, err := rec.listVPAs("ns1")
360 assert.NoError(t, err)
361 assert.NotEmpty(t, vpaList1)
362 assert.EqualValues(t, vpaList1[0].Name, "goldilocks-test1")
363 assert.EqualValues(t, vpaList1[1].Name, "goldilocks-test2")
364
365 // list all
366 vpaList2, err := rec.listVPAs("")
367 assert.NoError(t, err)
368 assert.NotEmpty(t, vpaList2)

Callers

nothing calls this directly

Calls 8

setupVPAForTestsFunction · 0.85
vpaUpdateModeForResourceFunction · 0.85
getVPAObjectMethod · 0.80
createVPAMethod · 0.80
GetInstanceFunction · 0.70
listVPAsMethod · 0.45

Tested by

no test coverage detected