1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-06 03:54:22 -04:00
v2fly/common/net/network_json_test.go
2016-02-04 10:43:04 +00:00

41 lines
932 B
Go

// +build json
package net_test
import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestArrayNetworkList(t *testing.T) {
v2testing.Current(t)
var list NetworkList
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
}
func TestStringNetworkList(t *testing.T) {
v2testing.Current(t)
var list NetworkList
err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
}
func TestInvalidJson(t *testing.T) {
v2testing.Current(t)
var list NetworkList
err := json.Unmarshal([]byte("0"), &list)
assert.Error(err).IsNotNil()
}