fn credential_heap()

in cert/cert-renewal/src/credential.rs [404:460]


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

        let policy = crate::RenewalPolicy {
            threshold: crate::Policy::Percentage(80),
            retry: crate::Policy::Percentage(4),
        };

        let cert_1 = test_cert(-1, 10);
        let cert_1 = Credential::new(
            "cert_1",
            &cert_1,
            "cert_key_1",
            policy.clone(),
            test_interface::new(),
        )
        .unwrap();

        let cert_2 = test_cert(-3, 5);
        let cert_2 = Credential::new(
            "cert_2",
            &cert_2,
            "cert_key_2",
            policy.clone(),
            test_interface::new(),
        )
        .unwrap();

        let cert_3 = test_cert(-5, 8);
        let cert_3 = Credential::new(
            "cert_3",
            &cert_3,
            "cert_key_3",
            policy,
            test_interface::new(),
        )
        .unwrap();

        let mut heap = CredentialHeap::new();
        assert!(heap.peek().is_none());
        assert!(heap.remove_next().is_none());

        assert!(heap.push(cert_1).is_some());
        assert!(heap.push(cert_2).is_some());
        assert!(heap.push(cert_3).is_none());

        assert!(heap.remove("cert_1", "cert_key_2").is_none());

        let cert = heap.remove_next().unwrap();
        assert_eq!("cert_2", cert.cert_id);

        let cert = heap.remove_next().unwrap();
        assert_eq!("cert_3", cert.cert_id);

        let cert = heap.remove_next().unwrap();
        assert_eq!("cert_1", cert.cert_id);
    }