@@ -26,7 +26,48 @@ func TestPosixBackupRestore(t *testing.T) {
2626 ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Minute )
2727 defer cancel ()
2828
29- t .Log ("Creating database" )
29+ var backupRepositories []* controlplane.BackupRepositorySpec
30+ var restoreRepository * controlplane.RestoreRepositorySpec
31+ var orchestratorOpts * controlplane.OrchestratorOpts
32+
33+ switch fixture .Orchestrator () {
34+ case "swarm" :
35+ backupRepositories = []* controlplane.BackupRepositorySpec {
36+ {
37+ Type : client .RepositoryTypePosix ,
38+ BasePath : pointerTo ("/backups" ),
39+ },
40+ }
41+ restoreRepository = & controlplane.RestoreRepositorySpec {
42+ Type : client .RepositoryTypePosix ,
43+ BasePath : pointerTo ("/backups" ),
44+ }
45+ orchestratorOpts = & controlplane.OrchestratorOpts {
46+ Swarm : & controlplane.SwarmOpts {
47+ ExtraVolumes : []* controlplane.ExtraVolumesSpec {
48+ {
49+ HostPath : tmpDir ,
50+ DestinationPath : "/backups" ,
51+ },
52+ },
53+ },
54+ }
55+ case "systemd" :
56+ backupRepositories = []* controlplane.BackupRepositorySpec {
57+ {
58+ Type : client .RepositoryTypePosix ,
59+ BasePath : & tmpDir ,
60+ },
61+ }
62+ restoreRepository = & controlplane.RestoreRepositorySpec {
63+ Type : client .RepositoryTypePosix ,
64+ BasePath : & tmpDir ,
65+ }
66+ default :
67+ t .Fatalf ("unsupported orchestrator '%s'" , fixture .Orchestrator ())
68+ }
69+
70+ tLog (t , "Creating database" )
3071
3172 db := fixture .NewDatabaseFixture (ctx , t , & controlplane.CreateDatabaseRequest {
3273 Spec : & controlplane.DatabaseSpec {
@@ -39,29 +80,16 @@ func TestPosixBackupRestore(t *testing.T) {
3980 Attributes : []string {"LOGIN" , "SUPERUSER" },
4081 },
4182 },
42- Port : pointerTo (0 ),
83+ Port : pointerTo (0 ),
84+ PatroniPort : pointerTo (0 ),
4385 Nodes : []* controlplane.DatabaseNodeSpec {
4486 {
4587 Name : "n1" ,
4688 HostIds : []controlplane.Identifier {controlplane .Identifier (host1 )},
4789 BackupConfig : & controlplane.BackupConfigSpec {
48- Repositories : []* controlplane.BackupRepositorySpec {
49- {
50- Type : client .RepositoryTypePosix ,
51- BasePath : pointerTo ("/backups" ),
52- },
53- },
54- },
55- OrchestratorOpts : & controlplane.OrchestratorOpts {
56- Swarm : & controlplane.SwarmOpts {
57- ExtraVolumes : []* controlplane.ExtraVolumesSpec {
58- {
59- HostPath : tmpDir ,
60- DestinationPath : "/backups" ,
61- },
62- },
63- },
90+ Repositories : backupRepositories ,
6491 },
92+ OrchestratorOpts : orchestratorOpts ,
6593 },
6694 },
6795 },
@@ -73,7 +101,7 @@ func TestPosixBackupRestore(t *testing.T) {
73101 Password : "password" ,
74102 }
75103
76- t . Log ( "Inserting test data" )
104+ tLog ( t , "Inserting test data" )
77105
78106 db .WithConnection (ctx , opts , t , func (conn * pgx.Conn ) {
79107 _ , err := conn .Exec (ctx , "CREATE TABLE foo (id INT PRIMARY KEY, val TEXT)" )
@@ -86,7 +114,7 @@ func TestPosixBackupRestore(t *testing.T) {
86114 require .NoError (t , err )
87115 })
88116
89- t . Log ( "Creating a full backup" )
117+ tLog ( t , "Creating a full backup" )
90118
91119 db .BackupDatabaseNode (ctx , BackupDatabaseNodeOptions {
92120 Node : "n1" ,
@@ -95,36 +123,33 @@ func TestPosixBackupRestore(t *testing.T) {
95123 },
96124 })
97125
98- t . Log ( "Deleting all data" )
126+ tLog ( t , "Deleting all data" )
99127
100128 db .WithConnection (ctx , opts , t , func (conn * pgx.Conn ) {
101129 _ , err := conn .Exec (ctx , "DELETE FROM foo" )
102130 require .NoError (t , err )
103131 })
104132
105- t . Log ( "Getting set name for latest full backup" )
133+ tLog ( t , "Getting set name for latest full backup" )
106134
107135 setName := fixture .LatestPosixBackup (t , host1 , tmpDir , string (db .ID ))
108136
109- t . Log ( "Creating another backup to ensure we can restore the correct one" )
137+ tLog ( t , "Creating another backup to ensure we can restore the correct one" )
110138 db .BackupDatabaseNode (ctx , BackupDatabaseNodeOptions {
111139 Node : "n1" ,
112140 Options : & controlplane.BackupOptions {
113141 Type : "full" ,
114142 },
115143 })
116144
117- t . Log ( "Restoring to the first backup" )
145+ tLog ( t , "Restoring to the first backup" )
118146
119147 err := db .RestoreDatabase (ctx , RestoreDatabaseOptions {
120148 RestoreConfig : & controlplane.RestoreConfigSpec {
121149 SourceDatabaseID : db .ID ,
122150 SourceNodeName : "n1" ,
123151 SourceDatabaseName : db .Spec .DatabaseName ,
124- Repository : & controlplane.RestoreRepositorySpec {
125- Type : client .RepositoryTypePosix ,
126- BasePath : pointerTo ("/backups" ),
127- },
152+ Repository : restoreRepository ,
128153 RestoreOptions : map [string ]string {
129154 "set" : strings .TrimSpace (setName ),
130155 "type" : "immediate" ,
@@ -133,7 +158,7 @@ func TestPosixBackupRestore(t *testing.T) {
133158 })
134159 require .NoError (t , err )
135160
136- t . Log ( "Validating restored data" )
161+ tLog ( t , "Validating restored data" )
137162
138163 // Validate that our data is restored
139164 db .WithConnection (ctx , opts , t , func (conn * pgx.Conn ) {
@@ -151,9 +176,7 @@ func TestPosixBackupRestore(t *testing.T) {
151176func TestS3BackupRestore (t * testing.T ) {
152177 t .Parallel ()
153178
154- if ! fixture .S3Enabled () {
155- t .Skip ("s3 not enabled for this fixture" )
156- }
179+ fixture .SkipIfS3Unsupported (t )
157180
158181 hostIDs := fixture .HostIDs ()
159182 host1 := hostIDs [0 ]
@@ -180,7 +203,8 @@ func TestS3BackupRestore(t *testing.T) {
180203 Attributes : []string {"LOGIN" , "SUPERUSER" },
181204 },
182205 },
183- Port : pointerTo (0 ),
206+ Port : pointerTo (0 ),
207+ PatroniPort : pointerTo (0 ),
184208 Nodes : []* controlplane.DatabaseNodeSpec {
185209 {Name : "n1" , HostIds : []controlplane.Identifier {controlplane .Identifier (hostIDs [0 ])}},
186210 {Name : "n2" , HostIds : []controlplane.Identifier {controlplane .Identifier (hostIDs [1 ])}},
@@ -280,9 +304,7 @@ func TestS3BackupRestore(t *testing.T) {
280304func TestS3AddNodeFromBackup (t * testing.T ) {
281305 t .Parallel ()
282306
283- if ! fixture .S3Enabled () {
284- t .Skip ("s3 not enabled for this fixture" )
285- }
307+ fixture .SkipIfS3Unsupported (t )
286308
287309 host1 := fixture .HostIDs ()[0 ]
288310 host2 := fixture .HostIDs ()[1 ]
@@ -309,7 +331,8 @@ func TestS3AddNodeFromBackup(t *testing.T) {
309331 Attributes : []string {"LOGIN" , "SUPERUSER" },
310332 },
311333 },
312- Port : pointerTo (0 ),
334+ Port : pointerTo (0 ),
335+ PatroniPort : pointerTo (0 ),
313336 Nodes : []* controlplane.DatabaseNodeSpec {
314337 {
315338 Name : "n1" ,
@@ -365,7 +388,8 @@ func TestS3AddNodeFromBackup(t *testing.T) {
365388 Attributes : []string {"LOGIN" , "SUPERUSER" },
366389 },
367390 },
368- Port : pointerTo (0 ),
391+ Port : pointerTo (0 ),
392+ PatroniPort : pointerTo (0 ),
369393 Nodes : []* controlplane.DatabaseNodeSpec {
370394 {
371395 Name : "n1" ,
@@ -414,9 +438,7 @@ func TestS3AddNodeFromBackup(t *testing.T) {
414438func TestS3CreateDBFromBackup (t * testing.T ) {
415439 t .Parallel ()
416440
417- if ! fixture .S3Enabled () {
418- t .Skip ("s3 not enabled for this fixture" )
419- }
441+ fixture .SkipIfS3Unsupported (t )
420442
421443 host1 := fixture .HostIDs ()[0 ]
422444 host2 := fixture .HostIDs ()[1 ]
@@ -443,7 +465,8 @@ func TestS3CreateDBFromBackup(t *testing.T) {
443465 Attributes : []string {"LOGIN" , "SUPERUSER" },
444466 },
445467 },
446- Port : pointerTo (0 ),
468+ Port : pointerTo (0 ),
469+ PatroniPort : pointerTo (0 ),
447470 Nodes : []* controlplane.DatabaseNodeSpec {
448471 {
449472 Name : "n1" ,
@@ -499,7 +522,8 @@ func TestS3CreateDBFromBackup(t *testing.T) {
499522 Attributes : []string {"LOGIN" , "SUPERUSER" },
500523 },
501524 },
502- Port : pointerTo (0 ),
525+ Port : pointerTo (0 ),
526+ PatroniPort : pointerTo (0 ),
503527 Nodes : []* controlplane.DatabaseNodeSpec {
504528 {
505529 Name : "n1" ,
@@ -546,6 +570,38 @@ func TestRemoveBackupConfig(t *testing.T) {
546570 ctx , cancel := context .WithTimeout (t .Context (), 5 * time .Minute )
547571 defer cancel ()
548572
573+ var backupRepositories []* controlplane.BackupRepositorySpec
574+ var orchestratorOpts * controlplane.OrchestratorOpts
575+
576+ switch fixture .Orchestrator () {
577+ case "swarm" :
578+ backupRepositories = []* controlplane.BackupRepositorySpec {
579+ {
580+ Type : client .RepositoryTypePosix ,
581+ BasePath : pointerTo ("/backups" ),
582+ },
583+ }
584+ orchestratorOpts = & controlplane.OrchestratorOpts {
585+ Swarm : & controlplane.SwarmOpts {
586+ ExtraVolumes : []* controlplane.ExtraVolumesSpec {
587+ {
588+ HostPath : tmpDir ,
589+ DestinationPath : "/backups" ,
590+ },
591+ },
592+ },
593+ }
594+ case "systemd" :
595+ backupRepositories = []* controlplane.BackupRepositorySpec {
596+ {
597+ Type : client .RepositoryTypePosix ,
598+ BasePath : & tmpDir ,
599+ },
600+ }
601+ default :
602+ t .Fatalf ("unsupported orchestrator '%s'" , fixture .Orchestrator ())
603+ }
604+
549605 tLog (t , "creating database" )
550606
551607 db := fixture .NewDatabaseFixture (ctx , t , & controlplane.CreateDatabaseRequest {
@@ -559,29 +615,16 @@ func TestRemoveBackupConfig(t *testing.T) {
559615 Attributes : []string {"LOGIN" , "SUPERUSER" },
560616 },
561617 },
562- Port : pointerTo (0 ),
618+ Port : pointerTo (0 ),
619+ PatroniPort : pointerTo (0 ),
563620 Nodes : []* controlplane.DatabaseNodeSpec {
564621 {
565622 Name : "n1" ,
566623 HostIds : []controlplane.Identifier {controlplane .Identifier (host1 )},
567624 BackupConfig : & controlplane.BackupConfigSpec {
568- Repositories : []* controlplane.BackupRepositorySpec {
569- {
570- Type : client .RepositoryTypePosix ,
571- BasePath : pointerTo ("/backups" ),
572- },
573- },
574- },
575- OrchestratorOpts : & controlplane.OrchestratorOpts {
576- Swarm : & controlplane.SwarmOpts {
577- ExtraVolumes : []* controlplane.ExtraVolumesSpec {
578- {
579- HostPath : tmpDir ,
580- DestinationPath : "/backups" ,
581- },
582- },
583- },
625+ Repositories : backupRepositories ,
584626 },
627+ OrchestratorOpts : orchestratorOpts ,
585628 },
586629 },
587630 },
@@ -599,21 +642,13 @@ func TestRemoveBackupConfig(t *testing.T) {
599642 Attributes : []string {"LOGIN" , "SUPERUSER" },
600643 },
601644 },
602- Port : pointerTo (0 ),
645+ Port : pointerTo (0 ),
646+ PatroniPort : pointerTo (0 ),
603647 Nodes : []* controlplane.DatabaseNodeSpec {
604648 {
605- Name : "n1" ,
606- HostIds : []controlplane.Identifier {controlplane .Identifier (host1 )},
607- OrchestratorOpts : & controlplane.OrchestratorOpts {
608- Swarm : & controlplane.SwarmOpts {
609- ExtraVolumes : []* controlplane.ExtraVolumesSpec {
610- {
611- HostPath : tmpDir ,
612- DestinationPath : "/backups" ,
613- },
614- },
615- },
616- },
649+ Name : "n1" ,
650+ HostIds : []controlplane.Identifier {controlplane .Identifier (host1 )},
651+ OrchestratorOpts : orchestratorOpts ,
617652 },
618653 },
619654 },
0 commit comments