Skip to content

Commit bc5af21

Browse files
committed
More comprehensive tests
1 parent 913caa8 commit bc5af21

3 files changed

Lines changed: 86 additions & 28 deletions

File tree

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
11
hs = {}
2-
if obj.status ~= nil then
3-
if obj.status.conditions ~= nil then
4-
for i, condition in ipairs(obj.status.conditions) do
5-
if condition.type == "Progressing" and condition.status == "False" then
6-
hs.status = "Degraded"
7-
hs.message = condition.message
8-
return hs
9-
end
10-
if condition.type == "Available" and condition.status == "True" then
11-
hs.status = "Healthy"
12-
hs.message = condition.message
13-
return hs
14-
end
2+
3+
-- Check if status exists
4+
if not obj.status then
5+
hs.status = "Degraded"
6+
hs.message = "No status available"
7+
return hs
8+
end
9+
10+
-- Initialize variables for conditions
11+
local available = false
12+
local progressing = false
13+
local availableMessage = ""
14+
local progressingMessage = ""
15+
16+
-- Check conditions
17+
if obj.status.conditions then
18+
for _, condition in ipairs(obj.status.conditions) do
19+
if condition.type == "Available" then
20+
available = condition.status == "True"
21+
availableMessage = condition.message or "Application availability status"
22+
elseif condition.type == "Progressing" then
23+
progressing = condition.status == "True"
24+
progressingMessage = condition.message or "Application progress status"
1525
end
1626
end
1727
end
1828

19-
hs.status = "Progressing"
20-
hs.message = "Waiting for SpinApp to be available"
29+
-- Check ready replicas if specified
30+
local readyReplicas = obj.status.readyReplicas or 0
31+
local desiredReplicas = obj.spec.replicas or 1
32+
33+
-- Determine status based on conditions
34+
if not available then
35+
hs.status = "Degraded"
36+
hs.message = availableMessage or "Application is not available"
37+
return hs
38+
end
39+
40+
if readyReplicas < desiredReplicas then
41+
hs.status = "Progressing"
42+
hs.message = string.format("Waiting for replicas to be ready (%d/%d)", readyReplicas, desiredReplicas)
43+
return hs
44+
end
45+
46+
if progressing then
47+
hs.status = "Progressing"
48+
hs.message = progressingMessage or "Application is still progressing"
49+
return hs
50+
end
51+
52+
-- All checks passed
53+
hs.status = "Healthy"
54+
hs.message = string.format("Application is healthy with %d/%d replicas ready", readyReplicas, desiredReplicas)
55+
2156
return hs
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
tests:
2+
- name: "healthy-spinapp"
3+
inputFile: "testdata/healthy.yaml"
4+
expected:
5+
status: "Healthy"
6+
message: "Application is healthy with 2/2 replicas ready"
7+
8+
- name: "degraded-spinapp"
9+
inputFile: "testdata/degraded.yaml"
10+
expected:
11+
status: "Degraded"
12+
message: "ReplicaSet has timed out progressing."
13+
14+
- name: "progressing-spinapp"
15+
inputFile: "testdata/progressing.yaml"
16+
expected:
17+
status: "Progressing"
18+
message: "Application is still progressing"
19+
20+
- name: "no-status"
21+
input:
22+
spec:
23+
replicas: 2
24+
expected:
25+
status: "Degraded"
26+
message: "No status available"
27+
28+
- name: "no-conditions"
29+
input:
30+
status:
31+
readyReplicas: 2
32+
spec:
33+
replicas: 2
34+
expected:
35+
status: "Degraded"
36+
message: "Application is not available"

resource_customizations/core.spinkube.dev/SpinApp/heath_test.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)