2018-02-17 17:37:09 -05:00
|
|
|
package policy_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
. "github.com/v2fly/v2ray-core/v5/app/policy"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/features/policy"
|
2018-02-17 17:37:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPolicy(t *testing.T) {
|
|
|
|
manager, err := New(context.Background(), &Config{
|
|
|
|
Level: map[uint32]*Policy{
|
2018-02-22 04:34:14 -05:00
|
|
|
0: {
|
2018-02-17 17:37:09 -05:00
|
|
|
Timeout: &Policy_Timeout{
|
|
|
|
Handshake: &Second{
|
|
|
|
Value: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2019-01-06 17:30:38 -05:00
|
|
|
common.Must(err)
|
2018-02-17 17:37:09 -05:00
|
|
|
|
2018-10-11 16:34:31 -04:00
|
|
|
pDefault := policy.SessionDefault()
|
2018-02-17 17:37:09 -05:00
|
|
|
|
2019-01-06 17:30:38 -05:00
|
|
|
{
|
|
|
|
p := manager.ForLevel(0)
|
|
|
|
if p.Timeouts.Handshake != 2*time.Second {
|
|
|
|
t.Error("expect 2 sec timeout, but got ", p.Timeouts.Handshake)
|
|
|
|
}
|
|
|
|
if p.Timeouts.ConnectionIdle != pDefault.Timeouts.ConnectionIdle {
|
|
|
|
t.Error("expect ", pDefault.Timeouts.ConnectionIdle, " sec timeout, but got ", p.Timeouts.ConnectionIdle)
|
|
|
|
}
|
|
|
|
}
|
2018-02-17 17:37:09 -05:00
|
|
|
|
2019-01-06 17:30:38 -05:00
|
|
|
{
|
|
|
|
p := manager.ForLevel(1)
|
|
|
|
if p.Timeouts.Handshake != pDefault.Timeouts.Handshake {
|
|
|
|
t.Error("expect ", pDefault.Timeouts.Handshake, " sec timeout, but got ", p.Timeouts.Handshake)
|
|
|
|
}
|
|
|
|
}
|
2018-02-17 17:37:09 -05:00
|
|
|
}
|