|
| 1 | +package k8s |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + appsv1 "k8s.io/api/apps/v1" |
| 9 | + v1 "k8s.io/api/core/v1" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | +) |
| 12 | + |
| 13 | +func TestErrorDeploymentNotAvailable(t *testing.T) { |
| 14 | + testCases := []struct { |
| 15 | + title string |
| 16 | + deploy *appsv1.Deployment |
| 17 | + expectedErr string |
| 18 | + }{ |
| 19 | + { |
| 20 | + title: "NoProgressingCondition", |
| 21 | + deploy: &appsv1.Deployment{ |
| 22 | + ObjectMeta: metav1.ObjectMeta{ |
| 23 | + Name: "foo", |
| 24 | + }, |
| 25 | + Status: appsv1.DeploymentStatus{ |
| 26 | + Conditions: []appsv1.DeploymentCondition{}, |
| 27 | + }, |
| 28 | + }, |
| 29 | + expectedErr: "Deployment foo is not available, missing 'Progressing' condition", |
| 30 | + }, |
| 31 | + { |
| 32 | + title: "DeploymentNotComplete", |
| 33 | + deploy: &appsv1.Deployment{ |
| 34 | + ObjectMeta: metav1.ObjectMeta{ |
| 35 | + Name: "foo", |
| 36 | + }, |
| 37 | + Status: appsv1.DeploymentStatus{ |
| 38 | + Conditions: []appsv1.DeploymentCondition{ |
| 39 | + { |
| 40 | + Type: appsv1.DeploymentProgressing, |
| 41 | + Status: v1.ConditionTrue, |
| 42 | + Reason: "ReplicaSetUpdated", |
| 43 | + Message: "bar", |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + expectedErr: "Deployment foo is not available as 'Progressing' condition indicates that the Deployment is not complete, status: True, reason: ReplicaSetUpdated, message: bar", |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + for _, tc := range testCases { |
| 53 | + tc := tc |
| 54 | + t.Run(tc.title, func(t *testing.T) { |
| 55 | + t.Parallel() |
| 56 | + err := NewDeploymentNotAvailableError(tc.deploy) |
| 57 | + assert.EqualError(t, err, tc.expectedErr) |
| 58 | + }) |
| 59 | + } |
| 60 | +} |
0 commit comments