MCPcopy
hub / github.com/kubernetes/kubectl / TestGenericScaleSimple

Function TestGenericScaleSimple

pkg/scale/scale_test.go:516–623  ·  view source on GitHub ↗

TestGenericScaleSimple exercises GenericScaler.ScaleSimple method

(t *testing.T)

Source from the content-addressed store, hash-verified

514
515// TestGenericScaleSimple exercises GenericScaler.ScaleSimple method
516func TestGenericScaleSimple(t *testing.T) {
517 // test data
518 scaleClient := createFakeScaleClient("deployments", "abc", 5, nil)
519 // expected actions
520 scaleClientExpectedAction := []string{"patch", "get", "update", "get", "update", "get", "get", "update", "get"}
521
522 // test scenarios
523 scenarios := []struct {
524 name string
525 precondition *ScalePrecondition
526 newSize int
527 targetGVR schema.GroupVersionResource
528 resName string
529 scaleGetter scale.ScalesGetter
530 expectError bool
531 }{
532 // scenario 0: scale up the "abc" deployment without precondition
533 {
534 name: "scale up the \"abc\" deployment without precondition",
535 precondition: nil,
536 newSize: 10,
537 targetGVR: deploygvr,
538 resName: "abc",
539 scaleGetter: scaleClient,
540 },
541 // scenario 1: scale up the "abc" deployment
542 {
543 name: "scale up the \"abc\" deployment",
544 precondition: &ScalePrecondition{10, ""},
545 newSize: 20,
546 targetGVR: deploygvr,
547 resName: "abc",
548 scaleGetter: scaleClient,
549 },
550 // scenario 2: scale down the "abc" deployment
551 {
552 name: "scale down the \"abs\" deployment",
553 precondition: &ScalePrecondition{20, ""},
554 newSize: 5,
555 targetGVR: deploygvr,
556 resName: "abc",
557 scaleGetter: scaleClient,
558 },
559 // scenario 3: precondition error, expected size is 1,
560 // note that the previous scenario (2) set the size to 5
561 {
562 name: "precondition error, expected size is 1",
563 precondition: &ScalePrecondition{1, ""},
564 newSize: 5,
565 targetGVR: deploygvr,
566 resName: "abc",
567 scaleGetter: scaleClient,
568 expectError: true,
569 },
570 // scenario 4: precondition is not validated when the precondition size is set to -1
571 {
572 name: "precondition is not validated when the size is set to -1",
573 precondition: &ScalePrecondition{-1, ""},

Callers

nothing calls this directly

Calls 4

ScaleSimpleMethod · 0.95
createFakeScaleClientFunction · 0.85
NewScalerFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…