Skip to content

Commit cb05508

Browse files
committed
HYPERFLEET-1017 - refactor: update tests and mocks for LastKnownReconciled rename
The HyperFleet API renamed the aggregated Available condition to LastKnownReconciled. Update all test fixtures, CEL expressions, and the mock API server to match.
1 parent a20ae57 commit cb05508

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

internal/client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func createMockCluster(id string) map[string]interface{} {
4141
"observed_generation": 5,
4242
},
4343
{
44-
"type": "Available",
44+
"type": "LastKnownReconciled",
4545
"status": "True",
4646
"created_time": "2025-01-01T09:00:00Z",
4747
"last_transition_time": "2025-01-01T10:00:00Z",
@@ -587,7 +587,7 @@ func TestFetchResources_NodePools(t *testing.T) {
587587
"observed_generation": 3,
588588
},
589589
{
590-
"type": "Available",
590+
"type": "LastKnownReconciled",
591591
"status": "True",
592592
"created_time": "2025-01-01T09:00:00Z",
593593
"last_transition_time": "2025-01-01T10:00:00Z",

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ func TestValidate_ParamsNoDependencies(t *testing.T) {
608608
md := &MessageDecisionConfig{
609609
Params: []Param{
610610
{Name: "a", Expr: `condition("Reconciled").status`},
611-
{Name: "b", Expr: `condition("Available").status`},
611+
{Name: "b", Expr: `condition("LastKnownReconciled").status`},
612612
},
613613
Result: "a == b",
614614
}

internal/engine/decision_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ func TestDecisionEngine_Evaluate_CustomExpressions(t *testing.T) {
338338
t.Run("condition function with custom condition name", func(t *testing.T) {
339339
cfg := &config.MessageDecisionConfig{
340340
Params: []config.Param{
341-
{Name: "is_available", Expr: `condition("Available").status == "True"`},
341+
{Name: "is_last_known_reconciled", Expr: `condition("LastKnownReconciled").status == "True"`},
342342
},
343-
Result: "is_available",
343+
Result: "is_last_known_reconciled",
344344
}
345345
engine, err := NewDecisionEngine(cfg)
346346
if err != nil {
@@ -353,17 +353,17 @@ func TestDecisionEngine_Evaluate_CustomExpressions(t *testing.T) {
353353
Generation: 1,
354354
Status: client.ResourceStatus{
355355
Conditions: []client.Condition{
356-
{Type: "Available", Status: "True", LastUpdatedTime: now},
356+
{Type: "LastKnownReconciled", Status: "True", LastUpdatedTime: now},
357357
},
358358
},
359359
}
360360

361361
decision := engine.Evaluate(resource, now)
362362
if !decision.ShouldPublish {
363-
t.Error("expected ShouldPublish=true for Available=True condition")
363+
t.Error("expected ShouldPublish=true for LastKnownReconciled=True condition")
364364
}
365365

366-
// Missing Available condition → zero-value → status="" → false
366+
// Missing LastKnownReconciled condition → zero-value → status="" → false
367367
resource2 := &client.Resource{
368368
ID: testResourceID,
369369
Kind: testResourceKind,
@@ -377,7 +377,7 @@ func TestDecisionEngine_Evaluate_CustomExpressions(t *testing.T) {
377377

378378
decision2 := engine.Evaluate(resource2, now)
379379
if decision2.ShouldPublish {
380-
t.Error("expected ShouldPublish=false when Available condition is missing")
380+
t.Error("expected ShouldPublish=false when LastKnownReconciled condition is missing")
381381
}
382382
})
383383
}
@@ -466,7 +466,7 @@ func TestBuildConditionsLookup(t *testing.T) {
466466
ObservedGeneration: 3,
467467
},
468468
{
469-
Type: "Available",
469+
Type: "LastKnownReconciled",
470470
Status: "False",
471471
LastUpdatedTime: now.Add(-5 * time.Minute),
472472
LastTransitionTime: now.Add(-10 * time.Minute),
@@ -491,12 +491,12 @@ func TestBuildConditionsLookup(t *testing.T) {
491491
t.Errorf("Reconciled observed_generation = %v, want 3", reconciled["observed_generation"])
492492
}
493493

494-
avail, ok := lookup["Available"]
494+
avail, ok := lookup["LastKnownReconciled"]
495495
if !ok {
496-
t.Fatal("missing Available condition")
496+
t.Fatal("missing LastKnownReconciled condition")
497497
}
498498
if avail["status"] != "False" {
499-
t.Errorf("Available status = %v, want False", avail["status"])
499+
t.Errorf("LastKnownReconciled status = %v, want False", avail["status"])
500500
}
501501
}
502502

test/integration/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func createMockClusterWithLabels(id string, generation int, observedGeneration i
8686
"conditions": []map[string]interface{}{
8787
reconciledCondition,
8888
{
89-
"type": "Available",
89+
"type": "LastKnownReconciled",
9090
"status": reconciledStatus,
9191
"created_time": "2025-01-01T09:00:00Z",
9292
"last_transition_time": "2025-01-01T10:00:00Z",

test/mock-hyperfleet-api/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ func buildConditions(generation int32) []map[string]any {
269269
conditions := []map[string]any{
270270
makeCondition("Reconciled", "True", "AllAdaptersReconciled",
271271
"All adapters reported Reconciled True for the current generation"),
272-
makeCondition("Available", "True", "AllAdaptersAvailable",
273-
"All adapters reported Available True for the same generation"),
272+
makeCondition("LastKnownReconciled", "True", "AllAdaptersReconciled",
273+
"All required adapters report Available=True for the tracked generation"),
274274
}
275275

276276
for _, adapter := range adapterNames {

0 commit comments

Comments
 (0)