mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Fix CertificationSet.add() and add test
This commit is contained in:
parent
6f5ca47709
commit
a6955eb81a
2 changed files with 27 additions and 0 deletions
|
@ -100,6 +100,9 @@ class CertificationSet(
|
||||||
val existing = certificationsForUserId[0]
|
val existing = certificationsForUserId[0]
|
||||||
if (existing.creationTime.before(certification.creationTime)) {
|
if (existing.creationTime.before(certification.creationTime)) {
|
||||||
certificationsForUserId.clear() // throw away older certifications
|
certificationsForUserId.clear() // throw away older certifications
|
||||||
|
}
|
||||||
|
// If our certification is newest
|
||||||
|
if (!existing.creationTime.after(certification.creationTime)) {
|
||||||
certificationsForUserId.add(certification)
|
certificationsForUserId.add(certification)
|
||||||
}
|
}
|
||||||
// else this certification is older, so ignore
|
// else this certification is older, so ignore
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.junit.jupiter.api.assertThrows
|
||||||
import org.pgpainless.wot.dijkstra.sq.*
|
import org.pgpainless.wot.dijkstra.sq.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class CertificationSetTest {
|
class CertificationSetTest {
|
||||||
|
@ -107,4 +108,27 @@ class CertificationSetTest {
|
||||||
assertEquals("0000000000000000000000000000000000000000 delegates to 1111111111111111111111111111111111111111\n" +
|
assertEquals("0000000000000000000000000000000000000000 delegates to 1111111111111111111111111111111111111111\n" +
|
||||||
"0000000000000000000000000000000000000000 certifies [Bob <bob@example.org>] 1111111111111111111111111111111111111111", twoCerts.toString())
|
"0000000000000000000000000000000000000000 certifies [Bob <bob@example.org>] 1111111111111111111111111111111111111111", twoCerts.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that for multiple Certifications over the same datum, only the most recent certifications are preserved`() {
|
||||||
|
val now = Date()
|
||||||
|
val fiveSecondsBefore = Date(now.time - 5000)
|
||||||
|
val old = Certification(alice, "Bob <bob@example.org>", bob, fiveSecondsBefore)
|
||||||
|
val new = Certification(alice, "Bob <bob@example.org>", bob, now)
|
||||||
|
val new2 = Certification(alice, bob, "Bob <bob@example.org>", now, null, true, 44, Depth.auto(10), RegexSet.wildcard())
|
||||||
|
|
||||||
|
var set = CertificationSet(alice, bob, mapOf())
|
||||||
|
set.add(old)
|
||||||
|
|
||||||
|
assertEquals(listOf(old), set.certifications["Bob <bob@example.org>"])
|
||||||
|
|
||||||
|
set.add(new)
|
||||||
|
assertEquals(listOf(new), set.certifications["Bob <bob@example.org>"])
|
||||||
|
|
||||||
|
set.add(new2)
|
||||||
|
assertEquals(listOf(new, new2), set.certifications["Bob <bob@example.org>"])
|
||||||
|
|
||||||
|
set.add(old)
|
||||||
|
assertEquals(listOf(new, new2), set.certifications["Bob <bob@example.org>"])
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue