@@ -19,88 +19,6 @@ import (
1919 "github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2020)
2121
22- func TestCheckBackupAnnotations (t * testing.T ) {
23- ctx := context .Background ()
24-
25- const crName = "check-backup-annotations"
26- const backupName = "backup1"
27- const ns = crName
28-
29- cr , err := readDefaultCR (crName , ns )
30- if err != nil {
31- t .Fatal (err )
32- }
33-
34- pgBackup , err := readDefaultBackup (backupName , ns )
35- if err != nil {
36- t .Fatal (err )
37- }
38- pgBackup .Spec .PGCluster = crName
39-
40- fakeClient , err := buildFakeClient (ctx , cr , pgBackup )
41- if err != nil {
42- t .Fatalf ("failed to build fake client: %v" , err )
43- }
44-
45- reconciler := backupReconciler ()
46- reconciler .Client = fakeClient
47-
48- reconcile := func () {
49- backupNsName := types.NamespacedName {Name : backupName , Namespace : ns }
50-
51- _ , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : backupNsName })
52- if err != nil {
53- t .Fatal (err )
54- }
55- if err := fakeClient .Get (ctx , client .ObjectKeyFromObject (cr ), cr ); err != nil {
56- t .Fatal (err )
57- }
58- if err := fakeClient .Get (ctx , client .ObjectKeyFromObject (pgBackup ), pgBackup ); err != nil {
59- t .Fatal (err )
60- }
61- }
62- initialAnnotations := make (map [string ]string )
63- for k , v := range cr .Annotations {
64- initialAnnotations [k ] = v
65- }
66-
67- reconcile ()
68-
69- startingAnnotations := make (map [string ]string )
70- for k , v := range cr .Annotations {
71- startingAnnotations [k ] = v
72- }
73-
74- if pgBackup .Status .State != v2 .BackupStarting {
75- t .Fatal ("backup state is not Starting" )
76- }
77-
78- // Annotations should not be deleted if pgbackup is not deleted
79- if err := checkBackupAnnotations (ctx , fakeClient , cr ); err != nil {
80- t .Fatal (err )
81- }
82- if err := fakeClient .Get (ctx , client .ObjectKeyFromObject (cr ), cr ); err != nil {
83- t .Fatal (err )
84- }
85- if ! compareMaps (startingAnnotations , cr .Annotations ) {
86- t .Fatal ("cr annotations changed after check backup annotation" )
87- }
88-
89- // Annotations should be deleted if pgbackup is deleted
90- if err := fakeClient .Delete (ctx , pgBackup ); err != nil {
91- t .Fatal (err )
92- }
93- if err := checkBackupAnnotations (ctx , fakeClient , cr ); err != nil {
94- t .Fatal (err )
95- }
96- if err := fakeClient .Get (ctx , client .ObjectKeyFromObject (cr ), cr ); err != nil {
97- t .Fatal (err )
98- }
99- if ! compareMaps (cr .Annotations , initialAnnotations ) {
100- t .Fatal ("annotations are have different size" , cr .Annotations , initialAnnotations )
101- }
102- }
103-
10422func compareMaps (x map [string ]string , y map [string ]string ) bool {
10523 if len (x ) != len (y ) {
10624 return false
0 commit comments