@@ -463,6 +463,7 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
463463 tests := map [string ]struct {
464464 backup * PerconaServerMySQLBackup
465465 storage * BackupStorageSpec
466+ cluster * PerconaServerMySQL
466467 expected bool
467468 }{
468469 "compress flag in backup spec args" : {
@@ -475,6 +476,7 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
475476 },
476477 },
477478 },
479+ cluster : & PerconaServerMySQL {},
478480 expected : true ,
479481 },
480482 "compress flag with algorithm value" : {
@@ -487,6 +489,7 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
487489 },
488490 },
489491 },
492+ cluster : & PerconaServerMySQL {},
490493 expected : true ,
491494 },
492495 "compress flag in storage args" : {
@@ -502,6 +505,7 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
502505 },
503506 },
504507 },
508+ cluster : & PerconaServerMySQL {},
505509 expected : true ,
506510 },
507511 "spec args take precedence, no compress there" : {
@@ -521,6 +525,7 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
521525 },
522526 },
523527 },
528+ cluster : & PerconaServerMySQL {},
524529 expected : false ,
525530 },
526531 "compress-threads alone does not count" : {
@@ -533,21 +538,115 @@ func TestPerconaServerMySQLBackup_IsCompressed(t *testing.T) {
533538 },
534539 },
535540 },
541+ cluster : & PerconaServerMySQL {},
536542 expected : false ,
537543 },
538544 "no container options" : {
539545 backup : & PerconaServerMySQLBackup {
540546 Spec : PerconaServerMySQLBackupSpec {},
541547 },
542548 storage : nil ,
549+ cluster : & PerconaServerMySQL {},
543550 expected : false ,
544551 },
552+ "compress in mysql configuration xtrabackup section" : {
553+ backup : & PerconaServerMySQLBackup {
554+ Spec : PerconaServerMySQLBackupSpec {},
555+ },
556+ cluster : & PerconaServerMySQL {
557+ Spec : PerconaServerMySQLSpec {
558+ MySQL : MySQLSpec {
559+ PodSpec : PodSpec {Configuration : "[mysqld]\n some=val\n [xtrabackup]\n compress=zstd\n " },
560+ },
561+ },
562+ },
563+ expected : true ,
564+ },
565+ "compress in mysql configuration xtrabackup section with spaces" : {
566+ backup : & PerconaServerMySQLBackup {
567+ Spec : PerconaServerMySQLBackupSpec {},
568+ },
569+ cluster : & PerconaServerMySQL {
570+ Spec : PerconaServerMySQLSpec {
571+ MySQL : MySQLSpec {
572+ PodSpec : PodSpec {Configuration : "[xtrabackup]\n compress = lz4\n " },
573+ },
574+ },
575+ },
576+ expected : true ,
577+ },
578+ "compress in mysql configuration with spaces inside section brackets" : {
579+ backup : & PerconaServerMySQLBackup {
580+ Spec : PerconaServerMySQLBackupSpec {},
581+ },
582+ cluster : & PerconaServerMySQL {
583+ Spec : PerconaServerMySQLSpec {
584+ MySQL : MySQLSpec {
585+ PodSpec : PodSpec {Configuration : "[ xtrabackup ]\n compress=zstd\n " },
586+ },
587+ },
588+ },
589+ expected : true ,
590+ },
591+ "compress key without value in mysql configuration" : {
592+ backup : & PerconaServerMySQLBackup {
593+ Spec : PerconaServerMySQLBackupSpec {},
594+ },
595+ cluster : & PerconaServerMySQL {
596+ Spec : PerconaServerMySQLSpec {
597+ MySQL : MySQLSpec {
598+ PodSpec : PodSpec {Configuration : "[xtrabackup]\n compress=\n " },
599+ },
600+ },
601+ },
602+ expected : false ,
603+ },
604+ "compress-threads alone in mysql configuration does not count" : {
605+ backup : & PerconaServerMySQLBackup {
606+ Spec : PerconaServerMySQLBackupSpec {},
607+ },
608+ cluster : & PerconaServerMySQL {
609+ Spec : PerconaServerMySQLSpec {
610+ MySQL : MySQLSpec {
611+ PodSpec : PodSpec {Configuration : "[xtrabackup]\n compress-threads=4\n " },
612+ },
613+ },
614+ },
615+ expected : false ,
616+ },
617+ "compress in wrong section of mysql configuration" : {
618+ backup : & PerconaServerMySQLBackup {
619+ Spec : PerconaServerMySQLBackupSpec {},
620+ },
621+ cluster : & PerconaServerMySQL {
622+ Spec : PerconaServerMySQLSpec {
623+ MySQL : MySQLSpec {
624+ PodSpec : PodSpec {Configuration : "[mysqld]\n compress=zstd\n " },
625+ },
626+ },
627+ },
628+ expected : false ,
629+ },
630+ "args take precedence over mysql configuration" : {
631+ backup : & PerconaServerMySQLBackup {
632+ Spec : PerconaServerMySQLBackupSpec {
633+ ContainerOptions : & BackupContainerOptions {
634+ Args : BackupContainerArgs {
635+ Xtrabackup : []string {"--compress" },
636+ },
637+ },
638+ },
639+ },
640+ cluster : & PerconaServerMySQL {},
641+ expected : true ,
642+ },
545643 }
546644
547645 for name , tt := range tests {
548646 t .Run (name , func (t * testing.T ) {
549- result := tt .backup .IsCompressed (tt .storage )
550- assert .Equal (t , tt .expected , result )
647+ var status PerconaServerMySQLBackupStatus
648+ status .Compressed = tt .backup .IsCompressed (tt .storage , tt .cluster .Spec .MySQL .Configuration )
649+ assert .Equal (t , tt .expected , status .Compressed )
551650 })
552651 }
553652}
0 commit comments