11package install
22
33import (
4+ "fmt"
45 "testing"
56
67 apps "k8s.io/api/apps/v1"
8+ core "k8s.io/api/core/v1"
79 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810)
911
@@ -15,6 +17,26 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
1517 msg string
1618 done bool
1719 }{
20+ {
21+ generation : 0 ,
22+ specReplicas : 1 ,
23+ status : apps.DeploymentStatus {
24+ ObservedGeneration : 1 ,
25+ Replicas : 1 ,
26+ UpdatedReplicas : 0 ,
27+ AvailableReplicas : 1 ,
28+ UnavailableReplicas : 0 ,
29+ Conditions : []apps.DeploymentCondition {
30+ {
31+ Type : apps .DeploymentProgressing ,
32+ Reason : "NotTimedOut" ,
33+ },
34+ },
35+ },
36+
37+ msg : "Waiting for rollout to finish: 0 out of 1 new replicas have been updated...\n " ,
38+ done : false ,
39+ },
1840 {
1941 generation : 0 ,
2042 specReplicas : 1 ,
@@ -52,9 +74,16 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
5274 UpdatedReplicas : 2 ,
5375 AvailableReplicas : 1 ,
5476 UnavailableReplicas : 1 ,
77+ Conditions : []apps.DeploymentCondition {
78+ {
79+ Type : apps .DeploymentAvailable ,
80+ Status : core .ConditionFalse ,
81+ Message : "Deployment does not have minimum availability." ,
82+ },
83+ },
5584 },
5685
57- msg : "Waiting for rollout to finish: 1 of 2 updated replicas are available.. .\n " ,
86+ msg : "Waiting for rollout to finish: deployment \" foo \" not available: Deployment does not have minimum availability .\n " ,
5887 done : false ,
5988 },
6089 {
@@ -64,13 +93,38 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
6493 ObservedGeneration : 1 ,
6594 Replicas : 2 ,
6695 UpdatedReplicas : 2 ,
67- AvailableReplicas : 2 ,
68- UnavailableReplicas : 0 ,
96+ AvailableReplicas : 1 ,
97+ UnavailableReplicas : 1 ,
98+ Conditions : []apps.DeploymentCondition {
99+ {
100+ Type : apps .DeploymentAvailable ,
101+ Status : core .ConditionTrue ,
102+ },
103+ },
69104 },
70105
71106 msg : "deployment \" foo\" successfully rolled out\n " ,
72107 done : true ,
73108 },
109+ {
110+ generation : 1 ,
111+ specReplicas : 2 ,
112+ status : apps.DeploymentStatus {
113+ ObservedGeneration : 1 ,
114+ Replicas : 2 ,
115+ UpdatedReplicas : 2 ,
116+ AvailableReplicas : 1 ,
117+ UnavailableReplicas : 1 ,
118+ Conditions : []apps.DeploymentCondition {
119+ {
120+ Type : "Fooing" ,
121+ Status : core .ConditionTrue ,
122+ },
123+ },
124+ },
125+ msg : "Waiting for rollout to finish: deployment \" foo\" missing condition \" Available\" \n " ,
126+ done : false ,
127+ },
74128 {
75129 generation : 2 ,
76130 specReplicas : 2 ,
@@ -87,33 +141,35 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
87141 },
88142 }
89143
90- for _ , test := range tests {
91- d := & apps.Deployment {
92- ObjectMeta : metav1.ObjectMeta {
93- Namespace : "bar" ,
94- Name : "foo" ,
95- UID : "8764ae47-9092-11e4-8393-42010af018ff" ,
96- Generation : test .generation ,
97- },
98- Spec : apps.DeploymentSpec {
99- Replicas : & test .specReplicas ,
100- },
101- Status : test .status ,
102- }
103- msg , done , err := DeploymentStatus (d )
104- if err != nil {
105- t .Fatalf ("DeploymentStatusViewer.Status(): %v" , err )
106- }
107- if done != test .done || msg != test .msg {
108- t .Errorf ("DeploymentStatusViewer.Status() for deployment with generation %d, %d replicas specified, and status %+v returned %q, %t, want %q, %t" ,
109- test .generation ,
110- test .specReplicas ,
111- test .status ,
112- msg ,
113- done ,
114- test .msg ,
115- test .done ,
116- )
117- }
144+ for i , test := range tests {
145+ t .Run (fmt .Sprintf ("%d" , i + 1 ), func (t * testing.T ) {
146+ d := & apps.Deployment {
147+ ObjectMeta : metav1.ObjectMeta {
148+ Namespace : "bar" ,
149+ Name : "foo" ,
150+ UID : "8764ae47-9092-11e4-8393-42010af018ff" ,
151+ Generation : test .generation ,
152+ },
153+ Spec : apps.DeploymentSpec {
154+ Replicas : & test .specReplicas ,
155+ },
156+ Status : test .status ,
157+ }
158+ msg , done , err := DeploymentStatus (d )
159+ if err != nil {
160+ t .Fatalf ("DeploymentStatusViewer.Status(): %v" , err )
161+ }
162+ if done != test .done || msg != test .msg {
163+ t .Errorf ("DeploymentStatusViewer.Status() for deployment with generation %d, %d replicas specified, and status %+v returned %q, %t, want %q, %t" ,
164+ test .generation ,
165+ test .specReplicas ,
166+ test .status ,
167+ msg ,
168+ done ,
169+ test .msg ,
170+ test .done ,
171+ )
172+ }
173+ })
118174 }
119175}
0 commit comments