@@ -23,6 +23,7 @@ import (
2323 "github.com/crunchydata/postgres-operator/internal/initialize"
2424 "github.com/crunchydata/postgres-operator/internal/naming"
2525 "github.com/crunchydata/postgres-operator/internal/testing/cmp"
26+ "github.com/crunchydata/postgres-operator/internal/testing/events"
2627 "github.com/crunchydata/postgres-operator/internal/testing/require"
2728 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2829)
@@ -783,3 +784,73 @@ postgres-operator.crunchydata.com/role: replica
783784 ` ))
784785 })
785786}
787+
788+ func TestPatroniLogSize (t * testing.T ) {
789+ ctx := context .Background ()
790+
791+ oneMeg := "1M"
792+ badSize := "notASize"
793+
794+ cluster := v1beta1.PostgresCluster {
795+ ObjectMeta : metav1.ObjectMeta {
796+ Name : "sometest" ,
797+ Namespace : "test-namespace" ,
798+ },
799+ Spec : v1beta1.PostgresClusterSpec {}}
800+
801+ t .Run ("Default" , func (t * testing.T ) {
802+ recorder := events .NewRecorder (t , runtime .Scheme )
803+ reconciler := & Reconciler {Recorder : recorder }
804+
805+ size := reconciler .patroniLogSize (ctx , & cluster )
806+
807+ assert .Equal (t , size , int64 (0 ))
808+ assert .Equal (t , len (recorder .Events ), 0 )
809+ })
810+
811+ t .Run ("NoSize" , func (t * testing.T ) {
812+ recorder := events .NewRecorder (t , runtime .Scheme )
813+ reconciler := & Reconciler {Recorder : recorder }
814+
815+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
816+ Log : & v1beta1.PatroniLogConfig {}}
817+
818+ size := reconciler .patroniLogSize (ctx , & cluster )
819+
820+ assert .Equal (t , size , int64 (0 ))
821+ assert .Equal (t , len (recorder .Events ), 0 )
822+ })
823+
824+ t .Run ("ValidSize" , func (t * testing.T ) {
825+ recorder := events .NewRecorder (t , runtime .Scheme )
826+ reconciler := & Reconciler {Recorder : recorder }
827+
828+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
829+ Log : & v1beta1.PatroniLogConfig {
830+ FileSize : & oneMeg ,
831+ }}
832+
833+ size := reconciler .patroniLogSize (ctx , & cluster )
834+
835+ assert .Equal (t , size , int64 (1000000 ))
836+ assert .Equal (t , len (recorder .Events ), 0 )
837+ })
838+
839+ t .Run ("BadSize" , func (t * testing.T ) {
840+ recorder := events .NewRecorder (t , runtime .Scheme )
841+ reconciler := & Reconciler {Recorder : recorder }
842+
843+ cluster .Spec .Patroni = & v1beta1.PatroniSpec {
844+ Log : & v1beta1.PatroniLogConfig {
845+ FileSize : & badSize ,
846+ }}
847+
848+ size := reconciler .patroniLogSize (ctx , & cluster )
849+
850+ assert .Equal (t , size , int64 (25000000 ))
851+ assert .Equal (t , len (recorder .Events ), 1 )
852+ assert .Equal (t , recorder .Events [0 ].Regarding .Name , cluster .Name )
853+ assert .Equal (t , recorder .Events [0 ].Reason , "InvalidPatroniLogFileSize" )
854+ assert .Equal (t , recorder .Events [0 ].Note , "Error when parsing spec.patroni.log.fileSize. File size will default to 25M." )
855+ })
856+ }
0 commit comments