[GH-18965] - Pass expire time from outside Cleanup method (#19008)
Pass expire time from outside Cleanup method Fixes #18965
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c198ef6e16
Коммит
0dbc74f6d5
@@ -14,9 +14,9 @@ type TokenStore struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// Cleanup provides a mock function with given fields:
|
||||
func (_m *TokenStore) Cleanup() {
|
||||
_m.Called()
|
||||
// Cleanup provides a mock function with given fields: expiryTime
|
||||
func (_m *TokenStore) Cleanup(expiryTime int64) {
|
||||
_m.Called(expiryTime)
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: token
|
||||
|
||||
42
store/storetest/tokens_store.go
Обычный файл
42
store/storetest/tokens_store.go
Обычный файл
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
)
|
||||
|
||||
func TestTokensStore(t *testing.T, ss store.Store) {
|
||||
t.Run("TokensCleanup", func(t *testing.T) { testTokensCleanup(t, ss) })
|
||||
}
|
||||
|
||||
func testTokensCleanup(t *testing.T, ss store.Store) {
|
||||
now := model.GetMillis()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
err := ss.Token().Save(&model.Token{
|
||||
Token: model.NewRandomString(model.TokenSize),
|
||||
CreateAt: now - int64(i),
|
||||
Type: model.TokenTypeOAuth,
|
||||
Extra: "",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
tokens, err := ss.Token().GetAllTokensByType(model.TokenTypeOAuth)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, tokens, 10)
|
||||
|
||||
ss.Token().Cleanup(now + int64(1))
|
||||
|
||||
tokens, err = ss.Token().GetAllTokensByType(model.TokenTypeOAuth)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, tokens, 0)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user