Skip to content

add unit test coverage for computing-unit.util resource helpers #6253

Description

@aglinxinyuan

Task Summary

Add computing-unit.util.spec.ts covering the pure resource-parsing / conversion / validation helpers exported from computing-unit.util.ts. These are plain functions — no Angular TestBed needed.

Background

frontend/src/app/common/util/computing-unit.util.ts exports ~15 pure helpers that parse Kubernetes CPU & memory resource strings (e.g. "500Mi", "1000m"), compute usage percentages, validate a unit name, and derive UI status/colors. None of them are directly unit-tested today.

export function parseResourceUnit(resource: string): string { ... }   // "500Mi" -> "Mi"
export function parseResourceNumber(resource: string): number { ... } // "2Gi"   -> 2
export function cpuResourceConversion(from: string, toUnit: string): string { ... }
export function memoryPercentage(usage: string, limit: string): number { ... }
export function validateName(trimmedName: string): string | null { ... }

Behavior to pin

Function Contract
parseResourceUnit "500Mi""Mi"; "2"""; "" and "NaN""NaN"; garbage → ""
parseResourceNumber "2Gi"2; "1.5Gi"1.5; "" / "NaN"0
cpuResourceConversion "1000m""1.0000" cores (empty target unit); respects the n/u/m/"" scale ladder and per-unit precision
cpuPercentage / memoryPercentage return 0 when either arg is "N/A" or the limit is ≤ 0; otherwise clamp the result at 100
findNearestValidStep returns 1 on an empty step list; returns the value when present; otherwise the closest step
validateName "" → empty-name error; a 129-char name → too-long error; a valid name → null
getComputingUnitBadgeColor "Running""green", "Pending""gold", else "red"
isComputingUnitShmTooLarge true only when the requested shared-memory (normalized to Mi) exceeds the selected memory

Follow size-formatter.util.spec.ts in the same folder as the style template (plain describe/it/expect, run with ng test).

Scope

  • New spec: frontend/src/app/common/util/computing-unit.util.spec.ts.
  • No production-code changes.

Task Type

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions