2016-01-15 08:34:33 -05:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package net_test
|
2015-11-01 17:01:15 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-15 08:34:33 -05:00
|
|
|
. "github.com/v2ray/v2ray-core/common/net"
|
2015-12-02 09:27:18 -05:00
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-11-01 17:01:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestArrayNetworkList(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2015-11-01 17:01:15 -05:00
|
|
|
|
|
|
|
var list NetworkList
|
|
|
|
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
|
|
|
|
assert.Error(err).IsNil()
|
2016-01-15 08:34:33 -05:00
|
|
|
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
|
|
|
|
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
|
2015-11-01 17:01:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStringNetworkList(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2015-11-01 17:01:15 -05:00
|
|
|
|
|
|
|
var list NetworkList
|
|
|
|
err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
|
|
|
|
assert.Error(err).IsNil()
|
2016-01-15 08:34:33 -05:00
|
|
|
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
|
|
|
|
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
|
2015-11-01 17:01:15 -05:00
|
|
|
}
|
2016-02-04 05:43:04 -05:00
|
|
|
|
2016-02-04 05:47:57 -05:00
|
|
|
func TestInvalidNetworkJson(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-02-04 05:43:04 -05:00
|
|
|
|
|
|
|
var list NetworkList
|
|
|
|
err := json.Unmarshal([]byte("0"), &list)
|
|
|
|
assert.Error(err).IsNotNil()
|
|
|
|
}
|