v2ray-core/testing/mocks/mockuserset.go

25 lines
528 B
Go
Raw Normal View History

2015-09-14 17:03:31 +00:00
package mocks
import (
2015-09-19 22:11:14 +00:00
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
2015-09-14 17:03:31 +00:00
)
type MockUserSet struct {
2015-09-19 22:11:14 +00:00
UserIds []user.ID
2015-09-14 17:03:31 +00:00
UserHashes map[string]int
2015-09-16 19:13:13 +00:00
Timestamps map[string]int64
2015-09-14 17:03:31 +00:00
}
2015-09-19 22:11:14 +00:00
func (us *MockUserSet) AddUser(user user.User) error {
2015-09-14 17:03:31 +00:00
us.UserIds = append(us.UserIds, user.Id)
return nil
}
2015-09-19 22:11:14 +00:00
func (us *MockUserSet) GetUser(userhash []byte) (*user.ID, int64, bool) {
2015-09-14 17:03:31 +00:00
idx, found := us.UserHashes[string(userhash)]
if found {
2015-09-16 19:13:13 +00:00
return &us.UserIds[idx], us.Timestamps[string(userhash)], true
2015-09-14 17:03:31 +00:00
}
2015-09-14 23:32:55 +00:00
return nil, 0, false
2015-09-14 17:03:31 +00:00
}