@@ -4,140 +4,106 @@ import (
4
4
"fmt"
5
5
"testing"
6
6
7
+ "github.com/stretchr/testify/assert"
7
8
apps "k8s.io/api/apps/v1"
8
9
core "k8s.io/api/core/v1"
9
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
11
)
11
12
12
13
func TestDeploymentStatusViewerStatus (t * testing.T ) {
13
14
tests := []struct {
14
- generation int64
15
- specReplicas int32
16
- status apps. DeploymentStatus
17
- msg string
18
- done bool
15
+ generation int64
16
+ status apps. DeploymentStatus
17
+ err error
18
+ msg string
19
+ done bool
19
20
}{
20
21
{
21
- generation : 0 ,
22
- specReplicas : 1 ,
23
22
status : apps.DeploymentStatus {
24
- ObservedGeneration : 1 ,
25
- Replicas : 1 ,
26
- UpdatedReplicas : 0 ,
27
- AvailableReplicas : 1 ,
28
- UnavailableReplicas : 0 ,
29
23
Conditions : []apps.DeploymentCondition {
30
24
{
31
25
Type : apps .DeploymentProgressing ,
32
- Reason : "NotTimedOut" ,
26
+ Reason : TimedOutReason ,
33
27
},
34
28
},
35
29
},
36
-
37
- msg : "Waiting for rollout to finish: 0 out of 1 new replicas have been updated...\n " ,
30
+ err : fmt .Errorf ("deployment \" foo\" exceeded its progress deadline" ),
38
31
done : false ,
39
32
},
40
33
{
41
- generation : 0 ,
42
- specReplicas : 1 ,
43
34
status : apps.DeploymentStatus {
44
- ObservedGeneration : 1 ,
45
- Replicas : 1 ,
46
- UpdatedReplicas : 0 ,
47
- AvailableReplicas : 1 ,
48
- UnavailableReplicas : 0 ,
35
+ Conditions : []apps.DeploymentCondition {
36
+ {
37
+ Type : apps .DeploymentProgressing ,
38
+ Reason : "NotTimedOut" ,
39
+ },
40
+ {
41
+ Type : apps .DeploymentAvailable ,
42
+ Status : core .ConditionTrue ,
43
+ },
44
+ },
45
+ },
46
+ msg : "deployment \" foo\" is up-to-date and available" ,
47
+ done : true ,
48
+ },
49
+ {
50
+ generation : 1 ,
51
+ status : apps.DeploymentStatus {
52
+ ObservedGeneration : 0 ,
49
53
},
50
-
51
- msg : "Waiting for rollout to finish: 0 out of 1 new replicas have been updated...\n " ,
54
+ msg : "waiting for spec update of deployment \" foo\" to be observed..." ,
52
55
done : false ,
53
56
},
54
57
{
55
- generation : 1 ,
56
- specReplicas : 1 ,
57
58
status : apps.DeploymentStatus {
58
- ObservedGeneration : 1 ,
59
- Replicas : 2 ,
60
- UpdatedReplicas : 1 ,
61
- AvailableReplicas : 2 ,
62
- UnavailableReplicas : 0 ,
59
+ Replicas : 5 ,
60
+ UpdatedReplicas : 3 ,
63
61
},
64
-
65
- msg : "Waiting for rollout to finish: 1 old replicas are pending termination...\n " ,
62
+ msg : "deployment \" foo\" waiting for 2 outdated replica(s) to be terminated" ,
66
63
done : false ,
67
64
},
68
65
{
69
- generation : 1 ,
70
- specReplicas : 2 ,
66
+ status : apps.DeploymentStatus {},
67
+ msg : fmt .Sprintf ("deployment \" foo\" not available: missing condition %q" , apps .DeploymentAvailable ),
68
+ done : false ,
69
+ },
70
+ {
71
71
status : apps.DeploymentStatus {
72
- ObservedGeneration : 1 ,
73
- Replicas : 2 ,
74
- UpdatedReplicas : 2 ,
75
- AvailableReplicas : 1 ,
76
- UnavailableReplicas : 1 ,
77
72
Conditions : []apps.DeploymentCondition {
78
73
{
79
74
Type : apps .DeploymentAvailable ,
80
75
Status : core .ConditionFalse ,
81
- Message : "Deployment does not have minimum availability. " ,
76
+ Message : "test message " ,
82
77
},
83
78
},
84
79
},
85
-
86
- msg : "Waiting for rollout to finish: deployment \" foo\" not available: Deployment does not have minimum availability.\n " ,
80
+ msg : "deployment \" foo\" not available: test message" ,
87
81
done : false ,
88
82
},
89
83
{
90
- generation : 1 ,
91
- specReplicas : 2 ,
92
84
status : apps.DeploymentStatus {
93
- ObservedGeneration : 1 ,
94
- Replicas : 2 ,
95
- UpdatedReplicas : 2 ,
96
- AvailableReplicas : 1 ,
97
- UnavailableReplicas : 1 ,
98
85
Conditions : []apps.DeploymentCondition {
99
86
{
100
- Type : apps .DeploymentAvailable ,
101
- Status : core .ConditionTrue ,
87
+ Type : apps .DeploymentAvailable ,
88
+ Status : core .ConditionUnknown ,
89
+ Message : "test message" ,
102
90
},
103
91
},
104
92
},
105
-
106
- msg : "deployment \" foo\" successfully rolled out\n " ,
107
- done : true ,
93
+ msg : "deployment \" foo\" not available: test message" ,
94
+ done : false ,
108
95
},
109
96
{
110
- generation : 1 ,
111
- specReplicas : 2 ,
112
97
status : apps.DeploymentStatus {
113
- ObservedGeneration : 1 ,
114
- Replicas : 2 ,
115
- UpdatedReplicas : 2 ,
116
- AvailableReplicas : 1 ,
117
- UnavailableReplicas : 1 ,
118
98
Conditions : []apps.DeploymentCondition {
119
99
{
120
- Type : "Fooing" ,
100
+ Type : apps . DeploymentAvailable ,
121
101
Status : core .ConditionTrue ,
122
102
},
123
103
},
124
104
},
125
- msg : "Waiting for rollout to finish: deployment \" foo\" missing condition \" Available\" \n " ,
126
- done : false ,
127
- },
128
- {
129
- generation : 2 ,
130
- specReplicas : 2 ,
131
- status : apps.DeploymentStatus {
132
- ObservedGeneration : 1 ,
133
- Replicas : 2 ,
134
- UpdatedReplicas : 2 ,
135
- AvailableReplicas : 2 ,
136
- UnavailableReplicas : 0 ,
137
- },
138
-
139
- msg : "Waiting for deployment spec update to be observed...\n " ,
140
- done : false ,
105
+ msg : "deployment \" foo\" is up-to-date and available" ,
106
+ done : true ,
141
107
},
142
108
}
143
109
@@ -147,29 +113,19 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
147
113
ObjectMeta : metav1.ObjectMeta {
148
114
Namespace : "bar" ,
149
115
Name : "foo" ,
150
- UID : "8764ae47-9092-11e4-8393-42010af018ff" ,
151
116
Generation : test .generation ,
152
117
},
153
- Spec : apps.DeploymentSpec {
154
- Replicas : & test .specReplicas ,
155
- },
156
118
Status : test .status ,
157
119
}
158
120
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
- )
121
+ assert := assert .New (t )
122
+ if test .err == nil {
123
+ assert .NoError (err )
124
+ } else {
125
+ assert .EqualError (err , test .err .Error ())
172
126
}
127
+ assert .Equal (test .done , done )
128
+ assert .Equal (test .msg , msg )
173
129
})
174
130
}
175
131
}
0 commit comments