From 10d733263d34c7e37d2ecd2ea5f8be0c685db47b Mon Sep 17 00:00:00 2001 From: V2Ray Date: Wed, 23 Sep 2015 20:14:12 +0200 Subject: [PATCH] Test case for TimedStringMap --- common/collect/timed_map_test.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 common/collect/timed_map_test.go diff --git a/common/collect/timed_map_test.go b/common/collect/timed_map_test.go new file mode 100644 index 00000000..c0a9f1d0 --- /dev/null +++ b/common/collect/timed_map_test.go @@ -0,0 +1,35 @@ +package collect + +import ( + "testing" + "time" + + "github.com/v2ray/v2ray-core/testing/unit" +) + +func TestTimedStringMap(t *testing.T) { + assert := unit.Assert(t) + + nowSec := time.Now().UTC().Unix() + m := NewTimedStringMap(3) + m.Set("Key1", "Value1", nowSec) + m.Set("Key2", "Value2", nowSec+20) + + v1, ok := m.Get("Key1") + assert.Bool(ok).IsTrue() + assert.String(v1.(string)).Equals("Value1") + + v2, ok := m.Get("Key2") + assert.Bool(ok).IsTrue() + assert.String(v2.(string)).Equals("Value2") + + tick := time.Tick(5 * time.Second) + <-tick + + v1, ok = m.Get("Key1") + assert.Bool(ok).IsFalse() + + v2, ok = m.Get("Key2") + assert.Bool(ok).IsTrue() + assert.String(v2.(string)).Equals("Value2") +}