server_spec_test.go 845 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package protocol_test
  2. import (
  3. "testing"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. . "github.com/v2ray/v2ray-core/common/protocol"
  6. "github.com/v2ray/v2ray-core/testing/assert"
  7. )
  8. type TestAccount struct {
  9. id int
  10. }
  11. func (this *TestAccount) Equals(account Account) bool {
  12. return account.(*TestAccount).id == this.id
  13. }
  14. func TestReceiverUser(t *testing.T) {
  15. assert := assert.On(t)
  16. account := &TestAccount{
  17. id: 0,
  18. }
  19. user := NewUser(UserLevel(0), "")
  20. user.Account = account
  21. rec := NewServerSpec(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), AlwaysValid(), user)
  22. assert.Bool(rec.HasUser(user)).IsTrue()
  23. account2 := &TestAccount{
  24. id: 1,
  25. }
  26. user2 := NewUser(UserLevel(0), "")
  27. user2.Account = account2
  28. assert.Bool(rec.HasUser(user2)).IsFalse()
  29. rec.AddUser(user2)
  30. assert.Bool(rec.HasUser(user2)).IsTrue()
  31. }