@@ -52,48 +52,49 @@ func TestCheckPartitions(t *testing.T) {
5252 // Build mock for each partitions
5353 for _ , p := range partitions {
5454 var tables []partition.Partition
55-
56- var table partition.Partition
57-
58- for i := 0 ; i <= p .Retention ; i ++ {
59- switch p .Interval {
60- case partition .Daily :
61- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , 0 , - i ))
62- case partition .Weekly :
63- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , 0 , - i * 7 ))
64- case partition .Quarterly :
65- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , i * - 3 , 0 ))
66- case partition .Monthly :
67- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , - i , 0 ))
68- case partition .Yearly :
69- table , _ = p .GeneratePartition (time .Now ().AddDate (- i , 0 , 0 ))
70- default :
71- t .Errorf ("unuspported partition interval in retention table mock" )
72- }
73-
74- postgreSQLMock .On ("GetColumnDataType" , table .Schema , table .ParentTable , p .PartitionKey ).Return (postgresql .Date , nil ).Once ()
75- tables = append (tables , table )
55+ var retentionTables []partition.Partition
56+ var preprovisionedTables []partition.Partition
57+
58+ // Create retention partitions
59+ forDate := time .Now ()
60+ switch p .Interval {
61+ case partition .Daily :
62+ retentionTables , _ = p .GetRetentionPartitions (forDate )
63+ case partition .Weekly :
64+ retentionTables , _ = p .GetRetentionPartitions (forDate )
65+ case partition .Quarterly :
66+ retentionTables , _ = p .GetRetentionPartitions (forDate )
67+ case partition .Monthly :
68+ retentionTables , _ = p .GetRetentionPartitions (forDate )
69+ case partition .Yearly :
70+ retentionTables , _ = p .GetRetentionPartitions (forDate )
71+ default :
72+ t .Errorf ("unuspported partition interval in retention table mock" )
7673 }
77-
78- for i := 0 ; i <= p .PreProvisioned ; i ++ {
79- switch p .Interval {
80- case partition .Daily :
81- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , 0 , i ))
82- case partition .Weekly :
83- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , 0 , i * 7 ))
84- case partition .Monthly :
85- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , i , 0 ))
86- case partition .Quarterly :
87- table , _ = p .GeneratePartition (time .Now ().AddDate (0 , i * 3 , 0 ))
88- case partition .Yearly :
89- table , _ = p .GeneratePartition (time .Now ().AddDate (i , 0 , 0 ))
90- default :
91- t .Errorf ("unuspported partition interval in preprovisonned table mock" )
92- }
93-
94- postgreSQLMock .On ("GetColumnDataType" , table .Schema , table .ParentTable , p .PartitionKey ).Return (postgresql .Date , nil ).Once ()
95- tables = append (tables , table )
74+ tables = append (tables , retentionTables ... )
75+
76+ // Create current partition
77+ currentPartition , _ := p .GeneratePartition (forDate )
78+ tables = append (tables , currentPartition )
79+
80+ // Create preprovisioned partitions
81+ switch p .Interval {
82+ case partition .Daily :
83+ preprovisionedTables , _ = p .GetPreProvisionedPartitions (forDate )
84+ case partition .Weekly :
85+ preprovisionedTables , _ = p .GetPreProvisionedPartitions (forDate )
86+ case partition .Monthly :
87+ preprovisionedTables , _ = p .GetPreProvisionedPartitions (forDate )
88+ case partition .Quarterly :
89+ preprovisionedTables , _ = p .GetPreProvisionedPartitions (forDate )
90+ case partition .Yearly :
91+ preprovisionedTables , _ = p .GetPreProvisionedPartitions (forDate )
92+ default :
93+ t .Errorf ("unuspported partition interval in preprovisonned table mock" )
9694 }
95+ tables = append (tables , preprovisionedTables ... )
96+
97+ postgreSQLMock .On ("GetColumnDataType" , p .Schema , p .Table , p .PartitionKey ).Return (postgresql .Date , nil ).Once ()
9798
9899 postgreSQLMock .On ("GetPartitionSettings" , p .Schema , p .Table ).Return (string (partition .Range ), p .PartitionKey , nil ).Once ()
99100
0 commit comments