@@ -2,6 +2,7 @@ package watcher
22
33import (
44 "context"
5+ "errors"
56 "testing"
67 "time"
78
@@ -310,3 +311,49 @@ func TestGetLatestBackup(t *testing.T) {
310311 })
311312 }
312313}
314+
315+ func TestGetLatestCommitTimestamp (t * testing.T ) {
316+ ctx := context .Background ()
317+
318+ tests := map [string ]struct {
319+ pods []client.Object
320+ backup * pgv2.PerconaPGBackup
321+ cluster * pgv2.PerconaPGCluster
322+ expectedErr error
323+ }{
324+ "primary pod not found due to invalid patroni version" : {
325+ pods : []client.Object {},
326+ backup : & pgv2.PerconaPGBackup {
327+ ObjectMeta : metav1.ObjectMeta {
328+ Name : "backup1" ,
329+ Namespace : "test-ns" ,
330+ },
331+ Spec : pgv2.PerconaPGBackupSpec {
332+ PGCluster : "test-cluster" ,
333+ RepoName : "repo1" ,
334+ },
335+ },
336+ cluster : & pgv2.PerconaPGCluster {
337+ ObjectMeta : metav1.ObjectMeta {
338+ Name : "test-cluster" ,
339+ Namespace : "test-ns" ,
340+ },
341+ Status : pgv2.PerconaPGClusterStatus {
342+ Patroni : pgv2.Patroni {
343+ Version : "error" ,
344+ },
345+ },
346+ },
347+ expectedErr : errors .New ("failed to get patroni version: Malformed version: error: primary pod not found" ),
348+ },
349+ }
350+ for name , tt := range tests {
351+ t .Run (name , func (t * testing.T ) {
352+ c := testutils .BuildFakeClient (tt .pods ... )
353+
354+ _ , err := GetLatestCommitTimestamp (ctx , c , nil , tt .cluster , tt .backup )
355+
356+ assert .EqualError (t , err , tt .expectedErr .Error ())
357+ })
358+ }
359+ }
0 commit comments