2016-07-25 14:48:09 +00:00
|
|
|
package protocol_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2016-07-25 19:31:16 +00:00
|
|
|
"time"
|
2016-07-25 14:48:09 +00:00
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
. "v2ray.com/core/common/protocol"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-07-25 14:48:09 +00:00
|
|
|
)
|
|
|
|
|
2016-07-25 19:31:16 +00:00
|
|
|
func TestAlwaysValidStrategy(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
strategy := AlwaysValid()
|
|
|
|
assert.Bool(strategy.IsValid()).IsTrue()
|
|
|
|
strategy.Invalidate()
|
|
|
|
assert.Bool(strategy.IsValid()).IsTrue()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeoutValidStrategy(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
strategy := BeforeTime(time.Now().Add(2 * time.Second))
|
|
|
|
assert.Bool(strategy.IsValid()).IsTrue()
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
assert.Bool(strategy.IsValid()).IsFalse()
|
|
|
|
|
|
|
|
strategy = BeforeTime(time.Now().Add(2 * time.Second))
|
|
|
|
strategy.Invalidate()
|
|
|
|
assert.Bool(strategy.IsValid()).IsFalse()
|
|
|
|
}
|