Skip to content

Commit

Permalink
check error msg for status of failed deploy in test
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
  • Loading branch information
somtochiama committed Jul 19, 2023
1 parent 5e22082 commit 4ec26b1
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions ssa/manager_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ssa

import (
"context"
"fmt"
"strings"
"testing"
"time"
Expand All @@ -28,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -114,19 +116,22 @@ func TestWaitForSet_failFast(t *testing.T) {

manager.SetOwnerLabels(objects, "infra", "default")
_, pvc := getFirstObject(objects, "PersistentVolumeClaim", id)
_, deploy := getFirstObject(objects, "Deployment", id)

deployObjMeta, _ := object.RuntimeToObjMeta(deploy)

cs, err := manager.ApplyAllStaged(ctx, objects, DefaultApplyOptions())
if err != nil {
t.Fatal(err)
}

var deploy = &appsv1.Deployment{
var clusterDeploy = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: id,
Namespace: id,
},
}
err = manager.client.Get(ctx, client.ObjectKeyFromObject(deploy), deploy)
err = manager.client.Get(ctx, client.ObjectKeyFromObject(deploy), clusterDeploy)
if err != nil {
t.Fatal(err)
}
Expand All @@ -140,14 +145,14 @@ func TestWaitForSet_failFast(t *testing.T) {
Reason: "ProgressDeadlineExceeded",
Message: "timeout progressing",
}
deploy.Status = appsv1.DeploymentStatus{
ObservedGeneration: deploy.Generation,
Replicas: *deploy.Spec.Replicas,
UpdatedReplicas: *deploy.Spec.Replicas,
UnavailableReplicas: *deploy.Spec.Replicas,
clusterDeploy.Status = appsv1.DeploymentStatus{
ObservedGeneration: clusterDeploy.Generation,
Replicas: *clusterDeploy.Spec.Replicas,
UpdatedReplicas: *clusterDeploy.Spec.Replicas,
UnavailableReplicas: *clusterDeploy.Spec.Replicas,
Conditions: []appsv1.DeploymentCondition{cond},
}
err = manager.client.Status().Update(ctx, deploy)
err = manager.client.Status().Update(ctx, clusterDeploy)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -184,9 +189,15 @@ func TestWaitForSet_failFast(t *testing.T) {
FailFast: false,
})

deployFailedMsg := fmt.Sprintf("%s status: '%s'", FmtObjMetadata(deployObjMeta), status.FailedStatus)

if err == nil || !strings.Contains(err.Error(), "timeout waiting for") {
t.Fatal("expected WaitForSet to timeout waiting for deployment")
}

if !strings.Contains(err.Error(), deployFailedMsg) {
t.Fatal("expected error to contain status of failed deployment")
}
})

t.Run("return early when failfast is set to true", func(t *testing.T) {
Expand All @@ -195,9 +206,16 @@ func TestWaitForSet_failFast(t *testing.T) {
Timeout: timeout,
FailFast: true,
})

deployFailedMsg := fmt.Sprintf("%s status: '%s'", FmtObjMetadata(deployObjMeta), status.FailedStatus)

if err == nil || !strings.Contains(err.Error(), "failed early") {
t.Fatal("expected WaitForSet to fail early due to stalled deployment")
}

if !strings.Contains(err.Error(), deployFailedMsg) {
t.Fatal("expected error to contain status of failed deployment")
}
})

t.Run("fail early even if there are still Progressing resources", func(t *testing.T) {
Expand Down Expand Up @@ -232,9 +250,14 @@ func TestWaitForSet_failFast(t *testing.T) {
FailFast: true,
})

deployFailedMsg := fmt.Sprintf("%s status: '%s'", FmtObjMetadata(deployObjMeta), status.FailedStatus)

if err == nil || !strings.Contains(err.Error(), "failed early") {
t.Fatal("expected WaitForSet to fail early due to stalled deployment")
}
})

if !strings.Contains(err.Error(), deployFailedMsg) {
t.Fatal("expected error to contain status of failed deployment")
}
})
}

0 comments on commit 4ec26b1

Please sign in to comment.