@@ -499,3 +499,49 @@ func TestCopyFromMeasurements_CopyFail(t *testing.T) {
499499 }
500500
501501}
502+
503+ func TestPartitionIntervalValidation (t * testing.T ) {
504+ a := assert .New (t )
505+ r := require .New (t )
506+
507+ const ImageName = "docker.io/postgres:17-alpine"
508+ pgContainer , err := postgres .Run (ctx ,
509+ ImageName ,
510+ postgres .WithDatabase ("mydatabase" ),
511+ testcontainers .WithWaitStrategy (
512+ wait .ForLog ("database system is ready to accept connections" ).
513+ WithOccurrence (2 ).
514+ WithStartupTimeout (5 * time .Second )),
515+ )
516+ r .NoError (err )
517+ defer func () { a .NoError (pgContainer .Terminate (ctx )) }()
518+
519+ connStr , _ := pgContainer .ConnectionString (ctx , "sslmode=disable" )
520+
521+ a .NoError (err )
522+
523+ opts := & CmdOpts {
524+ PartitionInterval : "1 minute" ,
525+ Retention : "14 days" ,
526+ BatchingDelay : time .Second ,
527+ }
528+
529+ _ , err = NewPostgresWriter (ctx , connStr , opts )
530+ a .EqualError (err , "Partition interval must be at least 1 hour, got: 1 minute" )
531+
532+ opts .PartitionInterval = "not an interval"
533+ _ , err = NewPostgresWriter (ctx , connStr , opts )
534+ a .Error (err )
535+
536+ validIntervals := []string {
537+ "3 days 4 hours" , "1 year" ,
538+ "P3D" , "PT3H" , "0-02" , "1 00:00:00" ,
539+ "P0-02" , "P1" , "2 weeks" ,
540+ }
541+
542+ for _ , interval := range validIntervals {
543+ opts .PartitionInterval = interval
544+ _ , err = NewPostgresWriter (ctx , connStr , opts )
545+ a .NoError ( err )
546+ }
547+ }
0 commit comments