@@ -110,15 +110,16 @@ func TestReconcilePGAdminUsers(t *testing.T) {
110110 assert .Equal (t , namespace , pgadmin .Namespace )
111111 assert .Equal (t , container , naming .ContainerPGAdmin )
112112
113- // Simulate a v7 version of pgAdmin by setting stdout to "7" for
114- // podexec call in reconcilePGAdminMajorVersion
115- _ , _ = stdout .Write ([]byte ("7" ))
113+ // Simulate a v7.1 version of pgAdmin by setting stdout to "7.1"
114+ // for podexec call in reconcilePGAdminVersion
115+ _ , _ = stdout .Write ([]byte ("7.1 " ))
116116 return nil
117117 }
118118
119119 assert .NilError (t , r .reconcilePGAdminUsers (ctx , pgadmin ))
120120 assert .Equal (t , calls , 1 , "PodExec should be called once" )
121121 assert .Equal (t , pgadmin .Status .MajorVersion , 7 )
122+ assert .Equal (t , pgadmin .Status .MinorVersion , "7.1" )
122123 assert .Equal (t , pgadmin .Status .ImageSHA , "fakeSHA" )
123124 })
124125
@@ -145,20 +146,58 @@ func TestReconcilePGAdminUsers(t *testing.T) {
145146 ) error {
146147 calls ++
147148
148- // Simulate a v7 version of pgAdmin by setting stdout to "7" for
149- // podexec call in reconcilePGAdminMajorVersion
150- _ , _ = stdout .Write ([]byte ("7" ))
149+ // Simulate a v7.1 version of pgAdmin by setting stdout to "7.1"
150+ // for podexec call in reconcilePGAdminVersion
151+ _ , _ = stdout .Write ([]byte ("7.1 " ))
151152 return nil
152153 }
153154
154155 assert .NilError (t , r .reconcilePGAdminUsers (ctx , pgadmin ))
155156 assert .Equal (t , calls , 1 , "PodExec should be called once" )
156157 assert .Equal (t , pgadmin .Status .MajorVersion , 7 )
158+ assert .Equal (t , pgadmin .Status .MinorVersion , "7.1" )
157159 assert .Equal (t , pgadmin .Status .ImageSHA , "newFakeSHA" )
158160 })
161+
162+ t .Run ("PodHealthyBadVersion" , func (t * testing.T ) {
163+ pgadmin := pgadmin .DeepCopy ()
164+ pod := pod .DeepCopy ()
165+
166+ pod .DeletionTimestamp = nil
167+ pod .Status .ContainerStatuses =
168+ []corev1.ContainerStatus {{Name : naming .ContainerPGAdmin }}
169+ pod .Status .ContainerStatuses [0 ].State .Running =
170+ new (corev1.ContainerStateRunning )
171+ pod .Status .ContainerStatuses [0 ].ImageID = "fakeSHA"
172+
173+ r := new (PGAdminReconciler )
174+ r .Reader = fake .NewClientBuilder ().WithObjects (pod ).Build ()
175+
176+ calls := 0
177+ r .PodExec = func (
178+ ctx context.Context , namespace , pod , container string ,
179+ stdin io.Reader , stdout , stderr io.Writer , command ... string ,
180+ ) error {
181+ calls ++
182+
183+ assert .Equal (t , pod , "pgadmin-123-0" )
184+ assert .Equal (t , namespace , pgadmin .Namespace )
185+ assert .Equal (t , container , naming .ContainerPGAdmin )
186+
187+ // set expected version to something completely wrong
188+ _ , _ = stdout .Write ([]byte ("woot" ))
189+ return nil
190+ }
191+
192+ assert .ErrorContains (t , r .reconcilePGAdminUsers (ctx , pgadmin ), "strconv.ParseFloat: parsing \" woot\" : invalid syntax" )
193+ assert .Equal (t , calls , 1 , "PodExec should be called once" )
194+ assert .Equal (t , pgadmin .Status .MajorVersion , 0 )
195+ assert .Equal (t , pgadmin .Status .MinorVersion , "" )
196+ assert .Equal (t , pgadmin .Status .ImageSHA , "" )
197+ })
159198}
160199
161- func TestReconcilePGAdminMajorVersion (t * testing.T ) {
200+ func TestReconcilePGAdminVersion (t * testing.T ) {
162201 ctx := context .Background ()
163202 pod := corev1.Pod {}
164203 pod .Namespace = "test-namespace"
@@ -180,30 +219,15 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {
180219 assert .Equal (t , namespace , "test-namespace" )
181220 assert .Equal (t , container , naming .ContainerPGAdmin )
182221
183- // Simulate a v7 version of pgAdmin by setting stdout to "7" for
184- // podexec call in reconcilePGAdminMajorVersion
185- _ , _ = stdout .Write ([]byte ("7 " ))
222+ // Simulate a v9.3 version of pgAdmin by setting stdout to "9.3"
223+ // for podexec call in reconcilePGAdminVersion
224+ _ , _ = stdout .Write ([]byte ("9.3 " ))
186225 return nil
187226 }
188227
189- version , err := reconciler .reconcilePGAdminMajorVersion (ctx , podExecutor )
228+ version , err := reconciler .reconcilePGAdminVersion (ctx , podExecutor )
190229 assert .NilError (t , err )
191- assert .Equal (t , version , 7 )
192- })
193-
194- t .Run ("FailedRetrieval" , func (t * testing.T ) {
195- reconciler .PodExec = func (
196- ctx context.Context , namespace , pod , container string ,
197- stdin io.Reader , stdout , stderr io.Writer , command ... string ,
198- ) error {
199- // Simulate the python call giving bad data (not a version int)
200- _ , _ = stdout .Write ([]byte ("asdfjkl;" ))
201- return nil
202- }
203-
204- version , err := reconciler .reconcilePGAdminMajorVersion (ctx , podExecutor )
205- assert .Check (t , err != nil )
206- assert .Equal (t , version , 0 )
230+ assert .Equal (t , version , "9.3" )
207231 })
208232
209233 t .Run ("PodExecError" , func (t * testing.T ) {
@@ -214,9 +238,9 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {
214238 return errors .New ("PodExecError" )
215239 }
216240
217- version , err := reconciler .reconcilePGAdminMajorVersion (ctx , podExecutor )
241+ version , err := reconciler .reconcilePGAdminVersion (ctx , podExecutor )
218242 assert .Check (t , err != nil )
219- assert .Equal (t , version , 0 )
243+ assert .Equal (t , version , "" )
220244 })
221245}
222246
0 commit comments