forked from Silverfish/proton-bridge
test: use clientmanager to logout fakeapi
This commit is contained in:
@ -148,10 +148,7 @@ func (api *FakePMAPI) AuthRefresh(token string) (*pmapi.Auth, error) {
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) Logout() {
|
||||
if err := api.DeleteAuth(); err != nil {
|
||||
api.log.WithError(err).Error("delete auth failed during logout")
|
||||
}
|
||||
api.ClearData()
|
||||
api.controller.clientManager.LogoutClient(api.userID)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) IsConnected() bool {
|
||||
@ -162,8 +159,6 @@ func (api *FakePMAPI) DeleteAuth() error {
|
||||
if err := api.checkAndRecordCall(DELETE, "/auth", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
// Logout will also emit change to auth channel
|
||||
api.sendAuth(nil)
|
||||
api.controller.deleteSession(api.uid)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ func NewController(cm *pmapi.ClientManager) *Controller {
|
||||
}
|
||||
|
||||
cm.SetClientConstructor(func(userID string) pmapi.Client {
|
||||
fakeAPI := New(controller)
|
||||
fakeAPI := New(controller, userID)
|
||||
controller.fakeAPIs = append(controller.fakeAPIs, fakeAPI)
|
||||
return fakeAPI
|
||||
})
|
||||
|
||||
@ -29,6 +29,7 @@ var errBadRequest = errors.New("NOT OK: 400 Bad Request")
|
||||
|
||||
type FakePMAPI struct {
|
||||
username string
|
||||
userID string
|
||||
controller *Controller
|
||||
eventIDGenerator idGenerator
|
||||
|
||||
@ -45,16 +46,19 @@ type FakePMAPI struct {
|
||||
log *logrus.Entry
|
||||
}
|
||||
|
||||
func New(controller *Controller) *FakePMAPI {
|
||||
func New(controller *Controller, userID string) *FakePMAPI {
|
||||
fakePMAPI := &FakePMAPI{
|
||||
controller: controller,
|
||||
log: logrus.WithField("pkg", "fakeapi"),
|
||||
userID: userID,
|
||||
}
|
||||
|
||||
fakePMAPI.addEvent(&pmapi.Event{
|
||||
EventID: fakePMAPI.eventIDGenerator.last("event"),
|
||||
Refresh: 0,
|
||||
More: 0,
|
||||
})
|
||||
|
||||
return fakePMAPI
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user