Skip to content

Commit be4001f

Browse files
authored
K8SPG-781 add TestGetLatestCommitTimestamp (#1309)
1 parent a1852ac commit be4001f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

percona/watcher/wal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func getLatestBackup(ctx context.Context, cli client.Client, cr *pgv2.PerconaPGC
162162
return latest, nil
163163
}
164164

165+
// GetLatestCommitTimestamp gets the timestamp of the latest commit.
165166
func GetLatestCommitTimestamp(ctx context.Context, cli client.Client, execCli *clientcmd.Client, cr *pgv2.PerconaPGCluster, backup *pgv2.PerconaPGBackup) (*metav1.Time, error) {
166167
log := logging.FromContext(ctx)
167168

percona/watcher/wal_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package watcher
22

33
import (
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

Comments
 (0)