1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
v2fly/testing/mocks/mockuserset.go

25 lines
528 B
Go
Raw Normal View History

2015-09-14 13:03:31 -04:00
package mocks
import (
2015-09-19 18:11:14 -04:00
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
2015-09-14 13:03:31 -04:00
)
type MockUserSet struct {
2015-09-19 18:11:14 -04:00
UserIds []user.ID
2015-09-14 13:03:31 -04:00
UserHashes map[string]int
2015-09-16 15:13:13 -04:00
Timestamps map[string]int64
2015-09-14 13:03:31 -04:00
}
2015-09-19 18:11:14 -04:00
func (us *MockUserSet) AddUser(user user.User) error {
2015-09-14 13:03:31 -04:00
us.UserIds = append(us.UserIds, user.Id)
return nil
}
2015-09-19 18:11:14 -04:00
func (us *MockUserSet) GetUser(userhash []byte) (*user.ID, int64, bool) {
2015-09-14 13:03:31 -04:00
idx, found := us.UserHashes[string(userhash)]
if found {
2015-09-16 15:13:13 -04:00
return &us.UserIds[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
}