@@ -683,6 +683,200 @@ func TestParseMGMTConfigMapUsageReportInterval(t *testing.T) {
683
683
}
684
684
}
685
685
686
+ func TestParseMGMTConfigMapUsageReportIntervalMaximum (t * testing.T ) {
687
+ t .Parallel ()
688
+ tests := []struct {
689
+ configMap * v1.ConfigMap
690
+ expectWarnings bool
691
+ expectInterval string
692
+ msg string
693
+ }{
694
+ {
695
+ configMap : & v1.ConfigMap {
696
+ Data : map [string ]string {
697
+ "license-token-secret-name" : "license-token" ,
698
+ "usage-report-interval" : "24h" ,
699
+ },
700
+ },
701
+ expectWarnings : false ,
702
+ expectInterval : "24h" ,
703
+ msg : "24h should be accepted (maximum allowed)" ,
704
+ },
705
+ {
706
+ configMap : & v1.ConfigMap {
707
+ Data : map [string ]string {
708
+ "license-token-secret-name" : "license-token" ,
709
+ "usage-report-interval" : "25h" ,
710
+ },
711
+ },
712
+ expectWarnings : true ,
713
+ expectInterval : "" ,
714
+ msg : "25h should be rejected (exceeds maximum)" ,
715
+ },
716
+ {
717
+ configMap : & v1.ConfigMap {
718
+ Data : map [string ]string {
719
+ "license-token-secret-name" : "license-token" ,
720
+ "usage-report-interval" : "1440m" ,
721
+ },
722
+ },
723
+ expectWarnings : false ,
724
+ expectInterval : "1440m" ,
725
+ msg : "1440m (24h) should be accepted" ,
726
+ },
727
+ {
728
+ configMap : & v1.ConfigMap {
729
+ Data : map [string ]string {
730
+ "license-token-secret-name" : "license-token" ,
731
+ "usage-report-interval" : "1441m" ,
732
+ },
733
+ },
734
+ expectWarnings : true ,
735
+ expectInterval : "" ,
736
+ msg : "1441m (>24h) should be rejected" ,
737
+ },
738
+ }
739
+
740
+ for _ , test := range tests {
741
+ t .Run (test .msg , func (t * testing.T ) {
742
+ result , warnings , err := ParseMGMTConfigMap (context .Background (), test .configMap , makeEventLogger ())
743
+ if err != nil {
744
+ t .Fatal (err )
745
+ }
746
+
747
+ if warnings != test .expectWarnings {
748
+ t .Errorf ("Expected warnings=%v, got warnings=%v" , test .expectWarnings , warnings )
749
+ }
750
+
751
+ if result .Interval != test .expectInterval {
752
+ t .Errorf ("Expected interval=%q, got interval=%q" , test .expectInterval , result .Interval )
753
+ }
754
+ })
755
+ }
756
+ }
757
+
758
+ func TestParseMGMTConfigMapUsageReportIntervalEdgeCases (t * testing.T ) {
759
+ t .Parallel ()
760
+ tests := []struct {
761
+ configMap * v1.ConfigMap
762
+ expectWarnings bool
763
+ expectInterval string
764
+ msg string
765
+ }{
766
+ // Test milliseconds (should be rejected due to unsupported unit)
767
+ {
768
+ configMap : & v1.ConfigMap {
769
+ Data : map [string ]string {
770
+ "license-token-secret-name" : "license-token" ,
771
+ "usage-report-interval" : "1000ms" ,
772
+ },
773
+ },
774
+ expectWarnings : true ,
775
+ expectInterval : "" ,
776
+ msg : "1000ms should be rejected (ms unit not allowed)" ,
777
+ },
778
+ {
779
+ configMap : & v1.ConfigMap {
780
+ Data : map [string ]string {
781
+ "license-token-secret-name" : "license-token" ,
782
+ "usage-report-interval" : "60000ms" ,
783
+ },
784
+ },
785
+ expectWarnings : true ,
786
+ expectInterval : "" ,
787
+ msg : "60000ms should be rejected (ms unit not allowed)" ,
788
+ },
789
+ // Test that large ms values are also rejected for unit, not value
790
+ {
791
+ configMap : & v1.ConfigMap {
792
+ Data : map [string ]string {
793
+ "license-token-secret-name" : "license-token" ,
794
+ "usage-report-interval" : "3600000ms" ,
795
+ },
796
+ },
797
+ expectWarnings : true ,
798
+ expectInterval : "" ,
799
+ msg : "3600000ms (1h) should be rejected (ms unit not allowed)" ,
800
+ },
801
+ // Test days (should be rejected by Go's ParseDuration)
802
+ {
803
+ configMap : & v1.ConfigMap {
804
+ Data : map [string ]string {
805
+ "license-token-secret-name" : "license-token" ,
806
+ "usage-report-interval" : "1d" ,
807
+ },
808
+ },
809
+ expectWarnings : true ,
810
+ expectInterval : "" ,
811
+ msg : "1d should be rejected (Go doesn't support 'd' unit)" ,
812
+ },
813
+ // Test values > 24h (valid in Go but should be rejected by max check)
814
+ {
815
+ configMap : & v1.ConfigMap {
816
+ Data : map [string ]string {
817
+ "license-token-secret-name" : "license-token" ,
818
+ "usage-report-interval" : "25h" ,
819
+ },
820
+ },
821
+ expectWarnings : true ,
822
+ expectInterval : "" ,
823
+ msg : "25h should be rejected (exceeds 24h maximum)" ,
824
+ },
825
+ {
826
+ configMap : & v1.ConfigMap {
827
+ Data : map [string ]string {
828
+ "license-token-secret-name" : "license-token" ,
829
+ "usage-report-interval" : "48h" ,
830
+ },
831
+ },
832
+ expectWarnings : true ,
833
+ expectInterval : "" ,
834
+ msg : "48h should be rejected (exceeds 24h maximum)" ,
835
+ },
836
+ // exactly 86400 seconds (24h)
837
+ {
838
+ configMap : & v1.ConfigMap {
839
+ Data : map [string ]string {
840
+ "license-token-secret-name" : "license-token" ,
841
+ "usage-report-interval" : "86400s" ,
842
+ },
843
+ },
844
+ expectWarnings : false ,
845
+ expectInterval : "86400s" ,
846
+ msg : "86400s (24h) should be accepted" ,
847
+ },
848
+ // 86401 seconds (24h + 1s)
849
+ {
850
+ configMap : & v1.ConfigMap {
851
+ Data : map [string ]string {
852
+ "license-token-secret-name" : "license-token" ,
853
+ "usage-report-interval" : "86401s" ,
854
+ },
855
+ },
856
+ expectWarnings : true ,
857
+ expectInterval : "" ,
858
+ msg : "86401s (>24h) should be rejected" ,
859
+ },
860
+ }
861
+
862
+ for _ , test := range tests {
863
+ t .Run (test .msg , func (t * testing.T ) {
864
+ result , warnings , err := ParseMGMTConfigMap (context .Background (), test .configMap , makeEventLogger ())
865
+ if err != nil {
866
+ t .Fatal (err )
867
+ }
868
+
869
+ if warnings != test .expectWarnings {
870
+ t .Errorf ("Expected warnings=%v, got warnings=%v" , test .expectWarnings , warnings )
871
+ }
872
+
873
+ if result .Interval != test .expectInterval {
874
+ t .Errorf ("Expected interval=%q, got interval=%q" , test .expectInterval , result .Interval )
875
+ }
876
+ })
877
+ }
878
+ }
879
+
686
880
func TestParseMGMTConfigMapResolverIPV6 (t * testing.T ) {
687
881
t .Parallel ()
688
882
tests := []struct {
0 commit comments