1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add test cases for hpa beta versions

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-01-18 12:38:49 +03:00
parent 9dc0eb55d7
commit 44a3ba38bf

View File

@ -43,6 +43,31 @@ const hpaV1 = {
} }
} }
const hpaV2Beta1 = {
apiVersion: "autoscaling/v2beta1",
kind: "HorizontalPodAutoscaler",
metadata: {
name: "hpav2beta1",
resourceVersion: "1",
uid: "hpav1",
namespace: "default",
selfLink: "/apis/autoscaling/v2beta1/namespaces/default/horizontalpodautoscalers/hpav2beta1",
},
spec: {
maxReplicas: 10,
scaleTargetRef: {
kind: "Deployment",
name: "hpav1deployment",
apiVersion: "apps/v1",
},
},
}
const hpaV2Beta2 = {
...hpaV2Beta1,
apiVersion: "autoscaling/v2beta2",
}
describe("getHorizontalPodAutoscalerMetrics", () => { describe("getHorizontalPodAutoscalerMetrics", () => {
let di: DiContainer; let di: DiContainer;
let getMetrics: (hpa: HorizontalPodAutoscaler) => string[]; let getMetrics: (hpa: HorizontalPodAutoscaler) => string[];
@ -1038,4 +1063,74 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
}); });
}); });
describe("HPA v2beta1", () => {
it("should use metric parser for hpa autoscaling/v2", () => {
const hpa = new HorizontalPodAutoscaler({
...hpaV2Beta1,
spec: {
...hpaV2Beta1.spec,
metrics: [
{
type: HpaMetricType.Resource,
resource: {
name: "cpu",
target: {
type: "Utilization",
averageUtilization: 50
}
}
}
]
}
});
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
});
it("should return unknown metrics for invalid v2 metric format", () => {
const hpa = new HorizontalPodAutoscaler({
...hpaV2Beta1,
spec: {
...hpaV2Beta1.spec,
metrics: [
{
type: HpaMetricType.Resource,
resource: {
name: "cpu",
targetAverageUtilization: 50
}
}
]
}
});
expect(getMetrics(hpa)[0]).toEqual("unknown / unknown");
});
});
describe("HPA v2beta2", () => {
it("should use metric parser for hpa autoscaling/v2", () => {
const hpa = new HorizontalPodAutoscaler({
...hpaV2Beta2,
spec: {
...hpaV2Beta2.spec,
metrics: [
{
type: HpaMetricType.Resource,
resource: {
name: "cpu",
target: {
type: "Utilization",
averageUtilization: 50
}
}
}
]
}
});
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
});
});
}); });