receiver_json_test.go 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build json
  2. package outbound_test
  3. import (
  4. "encoding/json"
  5. "testing"
  6. "github.com/v2ray/v2ray-core/common/protocol"
  7. . "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
  8. "github.com/v2ray/v2ray-core/testing/assert"
  9. )
  10. func TestConfigTargetParsing(t *testing.T) {
  11. assert := assert.On(t)
  12. rawJson := `{
  13. "address": "127.0.0.1",
  14. "port": 80,
  15. "users": [
  16. {
  17. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  18. "email": "love@v2ray.com",
  19. "level": 255
  20. }
  21. ]
  22. }`
  23. receiver := new(Receiver)
  24. err := json.Unmarshal([]byte(rawJson), &receiver)
  25. assert.Error(err).IsNil()
  26. assert.Destination(receiver.Destination).EqualsString("tcp:127.0.0.1:80")
  27. assert.Int(len(receiver.Accounts)).Equals(1)
  28. account := receiver.Accounts[0].Account.(*protocol.VMessAccount)
  29. assert.String(account.ID.String()).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
  30. }