mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-07 11:58:41 +00:00
Add Fake DNS support (#309)
Co-authored-by: Xiaokang Wang <xiaokangwang@outlook.com> Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Co-authored-by: kslr <kslrwang@gmail.com>
This commit is contained in:
parent
db32ce6fd9
commit
f50eff5ebb
43 changed files with 1351 additions and 301 deletions
common/cache
86
common/cache/lru_test.go
vendored
Normal file
86
common/cache/lru_test.go
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
package cache_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/xtls/xray-core/common/cache"
|
||||
)
|
||||
|
||||
func TestLruReplaceValue(t *testing.T) {
|
||||
lru := NewLru(2)
|
||||
lru.Put(2, 6)
|
||||
lru.Put(1, 5)
|
||||
lru.Put(1, 2)
|
||||
v, _ := lru.Get(1)
|
||||
if v != 2 {
|
||||
t.Error("should get 2", v)
|
||||
}
|
||||
v, _ = lru.Get(2)
|
||||
if v != 6 {
|
||||
t.Error("should get 6", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLruRemoveOld(t *testing.T) {
|
||||
lru := NewLru(2)
|
||||
v, ok := lru.Get(2)
|
||||
if ok {
|
||||
t.Error("should get nil", v)
|
||||
}
|
||||
lru.Put(1, 1)
|
||||
lru.Put(2, 2)
|
||||
v, _ = lru.Get(1)
|
||||
if v != 1 {
|
||||
t.Error("should get 1", v)
|
||||
}
|
||||
lru.Put(3, 3)
|
||||
v, ok = lru.Get(2)
|
||||
if ok {
|
||||
t.Error("should get nil", v)
|
||||
}
|
||||
lru.Put(4, 4)
|
||||
v, ok = lru.Get(1)
|
||||
if ok {
|
||||
t.Error("should get nil", v)
|
||||
}
|
||||
v, _ = lru.Get(3)
|
||||
if v != 3 {
|
||||
t.Error("should get 3", v)
|
||||
}
|
||||
v, _ = lru.Get(4)
|
||||
if v != 4 {
|
||||
t.Error("should get 4", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetKeyFromValue(t *testing.T) {
|
||||
lru := NewLru(2)
|
||||
lru.Put(3, 3)
|
||||
lru.Put(2, 2)
|
||||
lru.GetKeyFromValue(3)
|
||||
lru.Put(1, 1)
|
||||
v, ok := lru.GetKeyFromValue(2)
|
||||
if ok {
|
||||
t.Error("should get nil", v)
|
||||
}
|
||||
v, _ = lru.GetKeyFromValue(3)
|
||||
if v != 3 {
|
||||
t.Error("should get 3", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeekKeyFromValue(t *testing.T) {
|
||||
lru := NewLru(2)
|
||||
lru.Put(3, 3)
|
||||
lru.Put(2, 2)
|
||||
lru.PeekKeyFromValue(3)
|
||||
lru.Put(1, 1)
|
||||
v, ok := lru.PeekKeyFromValue(3)
|
||||
if ok {
|
||||
t.Error("should get nil", v)
|
||||
}
|
||||
v, _ = lru.PeekKeyFromValue(2)
|
||||
if v != 2 {
|
||||
t.Error("should get 2", v)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue