Add the Proxy reconciler state machine with action-table, phase, and envtest suites
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
112
internal/controller/status_test.go
Normal file
112
internal/controller/status_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
crawlv1alpha1 "gitea.home.hrajfrisbee.cz/kacerr/egress-proxies-operator/api/v1alpha1"
|
||||
)
|
||||
|
||||
func TestComputePhase_truthTable(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cond := func(condType string, status metav1.ConditionStatus, reason string) metav1.Condition {
|
||||
return metav1.Condition{Type: condType, Status: status, Reason: reason}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
deleting bool
|
||||
conditions []metav1.Condition
|
||||
want crawlv1alpha1.ProxyPhase
|
||||
}{
|
||||
{
|
||||
name: "deletionTimestamp wins over everything",
|
||||
deleting: true,
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionTrue, ReasonCreated),
|
||||
cond(crawlv1alpha1.ConditionHealthy, metav1.ConditionTrue, "Probing"),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseDeleting,
|
||||
},
|
||||
{
|
||||
name: "no conditions is Pending",
|
||||
want: crawlv1alpha1.PhasePending,
|
||||
},
|
||||
{
|
||||
name: "provisioning in progress",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionFalse, ReasonProvisioning),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseProvisioning,
|
||||
},
|
||||
{
|
||||
name: "replacing counts as provisioning",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionFalse, ReasonReplacing),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseProvisioning,
|
||||
},
|
||||
{
|
||||
name: "quota exhaustion is not Failed",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionFalse, ReasonQuotaExceeded),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseProvisioning,
|
||||
},
|
||||
{
|
||||
name: "permanent error is Failed",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionFalse, ReasonPermanentError),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseFailed,
|
||||
},
|
||||
{
|
||||
name: "provisioned without a health verdict stays Provisioning",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionTrue, ReasonCreated),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseProvisioning,
|
||||
},
|
||||
{
|
||||
name: "provisioned with Healthy Unknown stays Provisioning",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionTrue, ReasonCreated),
|
||||
cond(crawlv1alpha1.ConditionHealthy, metav1.ConditionUnknown, "NoProbeYet"),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseProvisioning,
|
||||
},
|
||||
{
|
||||
name: "provisioned and healthy is Ready",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionTrue, ReasonCreated),
|
||||
cond(crawlv1alpha1.ConditionHealthy, metav1.ConditionTrue, "Probing"),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseReady,
|
||||
},
|
||||
{
|
||||
name: "provisioned but unhealthy is Unhealthy",
|
||||
conditions: []metav1.Condition{
|
||||
cond(crawlv1alpha1.ConditionProvisioned, metav1.ConditionTrue, ReasonCreated),
|
||||
cond(crawlv1alpha1.ConditionHealthy, metav1.ConditionFalse, "ProbeFailed"),
|
||||
},
|
||||
want: crawlv1alpha1.PhaseUnhealthy,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := &crawlv1alpha1.Proxy{}
|
||||
p.Status.Conditions = tc.conditions
|
||||
if tc.deleting {
|
||||
now := metav1.Now()
|
||||
p.DeletionTimestamp = &now
|
||||
}
|
||||
if got := computePhase(p); got != tc.want {
|
||||
t.Errorf("computePhase() = %s, want %s", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user