1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-17 08:23:41 -04:00
v2fly/proxy/vmess/protocol/user/testing/mocks/mockuserset.go

26 lines
585 B
Go
Raw Normal View History

2015-09-14 13:03:31 -04:00
package mocks
import (
2015-12-07 14:32:38 -05:00
"github.com/v2ray/v2ray-core/proxy/vmess"
2016-01-12 05:38:43 -05:00
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
2015-09-14 13:03:31 -04:00
)
type MockUserSet struct {
2015-12-07 14:32:38 -05:00
Users []vmess.User
2015-09-14 13:03:31 -04:00
UserHashes map[string]int
2016-01-12 05:38:43 -05:00
Timestamps map[string]user.Timestamp
2015-09-14 13:03:31 -04:00
}
2015-12-07 14:32:38 -05:00
func (us *MockUserSet) AddUser(user vmess.User) error {
2015-10-30 19:38:31 -04:00
us.Users = append(us.Users, user)
2015-09-14 13:03:31 -04:00
return nil
}
2016-01-12 05:38:43 -05:00
func (us *MockUserSet) GetUser(userhash []byte) (vmess.User, user.Timestamp, bool) {
2015-09-14 13:03:31 -04:00
idx, found := us.UserHashes[string(userhash)]
if found {
2015-10-30 19:38:31 -04:00
return us.Users[idx], us.Timestamps[string(userhash)], true
2015-09-14 13:03:31 -04:00
}
2015-09-14 19:32:55 -04:00
return nil, 0, false
2015-09-14 13:03:31 -04:00
}