mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-08 01:27:35 -05:00
test code for validation strategy
This commit is contained in:
parent
2034d54bab
commit
f4aa50a160
@ -30,7 +30,7 @@ type TimeoutValidStrategy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BeforeTime(t time.Time) ValidationStrategy {
|
func BeforeTime(t time.Time) ValidationStrategy {
|
||||||
return TimeoutValidStrategy{
|
return &TimeoutValidStrategy{
|
||||||
until: t,
|
until: t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ func (this TimeoutValidStrategy) IsValid() bool {
|
|||||||
return this.until.After(time.Now())
|
return this.until.After(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this TimeoutValidStrategy) Invalidate() {
|
func (this *TimeoutValidStrategy) Invalidate() {
|
||||||
this.until = time.Time{}
|
this.until = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package protocol_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
. "github.com/v2ray/v2ray-core/common/protocol"
|
. "github.com/v2ray/v2ray-core/common/protocol"
|
||||||
@ -16,7 +17,7 @@ func (this *TestAccount) Equals(account Account) bool {
|
|||||||
return account.(*TestAccount).id == this.id
|
return account.(*TestAccount).id == this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReceiverUser(t *testing.T) {
|
func TestServerSpecUser(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
account := &TestAccount{
|
account := &TestAccount{
|
||||||
@ -37,3 +38,25 @@ func TestReceiverUser(t *testing.T) {
|
|||||||
rec.AddUser(user2)
|
rec.AddUser(user2)
|
||||||
assert.Bool(rec.HasUser(user2)).IsTrue()
|
assert.Bool(rec.HasUser(user2)).IsTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user