fn calculate_renewal_times()

in cert/cert-renewal/src/credential.rs [256:319]


    fn calculate_renewal_times() {
        crate::test_time::reset();

        // Bad cert: not_after is before not_before.
        let cert = test_cert(5, 1);
        renewal_times(
            &cert,
            &crate::RenewalPolicy {
                threshold: crate::Policy::Percentage(80),
                retry: crate::Policy::Percentage(4),
            },
        )
        .unwrap_err();

        // This function should not be called for expired certs.
        let cert = test_cert(-10, -5);
        renewal_times(
            &cert,
            &crate::RenewalPolicy {
                threshold: crate::Policy::Percentage(50),
                retry: crate::Policy::Percentage(4),
            },
        )
        .unwrap_err();

        // Check calculation for cert within its renewal threshold.
        let cert = test_cert(-60, 40);
        assert_eq!(
            (crate::Time::from(4), 4),
            renewal_times(
                &cert,
                &crate::RenewalPolicy {
                    threshold: crate::Policy::Percentage(50),
                    retry: crate::Policy::Percentage(4),
                },
            )
            .unwrap()
        );

        // Check calculation for cert not within its renewal threshold.
        let cert = test_cert(-5, 5);
        assert_eq!(
            (crate::Time::from(1), 2),
            renewal_times(
                &cert,
                &crate::RenewalPolicy {
                    threshold: crate::Policy::Percentage(60),
                    retry: crate::Policy::Percentage(20),
                }
            )
            .unwrap()
        );
        assert_eq!(
            (crate::Time::from(4), 1),
            renewal_times(
                &cert,
                &crate::RenewalPolicy {
                    threshold: crate::Policy::Time(1),
                    retry: crate::Policy::Time(1),
                }
            )
            .unwrap()
        );
    }