Skip to content

Commit b9afae2

Browse files
committed
test: migrate DnsCacheTest to kotest
1 parent 1debde7 commit b9afae2

File tree

2 files changed

+50
-55
lines changed

2 files changed

+50
-55
lines changed

library/src/test/java/com/alibaba/dcm/DnsCacheTest.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.alibaba.dcm
2+
3+
import io.kotest.core.spec.style.AnnotationSpec
4+
import io.kotest.matchers.shouldBe
5+
import io.kotest.matchers.shouldNotBe
6+
import java.text.SimpleDateFormat
7+
import java.util.*
8+
9+
/**
10+
* @author Jerry Lee (oldratlee at gmail dot com)
11+
*/
12+
class DnsCacheTests : AnnotationSpec() {
13+
@Test
14+
fun test_equals() {
15+
val expiration = System.currentTimeMillis()
16+
val entry1 = DnsCacheEntry("a.com", arrayOf("1.1.1.1"), expiration)
17+
val entry2 = DnsCacheEntry("b.com", arrayOf("1.1.1.2"), expiration)
18+
val entry3 = DnsCacheEntry("c.com", arrayOf("1.1.1.2"), expiration)
19+
val entry4 = DnsCacheEntry("d.com", arrayOf("1.1.1.2"), expiration)
20+
21+
val dnsCache1 = DnsCache(
22+
listOf(entry1, entry2),
23+
listOf(entry3))
24+
val dnsCache2 = DnsCache(
25+
listOf(entry1, entry2),
26+
listOf(entry4))
27+
28+
dnsCache1 shouldNotBe dnsCache2
29+
}
30+
31+
@Test
32+
fun test_toString() {
33+
val expiration = System.currentTimeMillis()
34+
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
35+
val date = dateFormat.format(Date(expiration))
36+
37+
val entry1 = DnsCacheEntry("a.com", arrayOf("1.1.1.1"), expiration)
38+
val entry2 = DnsCacheEntry("b.com", arrayOf("1.1.1.2"), expiration)
39+
val entry3 = DnsCacheEntry("c.com", arrayOf("1.1.1.2"), expiration)
40+
41+
val dnsCache = DnsCache(
42+
listOf(entry1, entry2),
43+
listOf(entry3))
44+
45+
val expected = String.format("DnsCache{cache=[DnsCacheEntry{host='a.com', ips=[1.1.1.1], expiration=%s}" +
46+
", DnsCacheEntry{host='b.com', ips=[1.1.1.2], expiration=%<s}]" +
47+
", negativeCache=[DnsCacheEntry{host='c.com', ips=[1.1.1.2], expiration=%<s}]}", date)
48+
dnsCache.toString() shouldBe expected
49+
}
50+
}

0 commit comments

Comments
 (0)