-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update last use time when api token is used (#210)
Because - we want users to be able to target the tokens that can be deprecated. This commit - Update token data when the token is used.
- Loading branch information
1 parent
319c188
commit 10fa9e2
Showing
8 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/DATA-DOG/go-sqlmock" | ||
qt "github.com/frankban/quicktest" | ||
"github.com/go-redis/redismock/v9" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func mockDBRepository() (sqlmock.Sqlmock, *sql.DB, Repository, error) { | ||
sqldb, mock, err := sqlmock.New() | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
gormdb, err := gorm.Open(postgres.New(postgres.Config{ | ||
Conn: sqldb, | ||
})) | ||
|
||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
redisClient, _ := redismock.NewClientMock() | ||
repository := NewRepository(gormdb, redisClient) | ||
|
||
return mock, sqldb, repository, err | ||
} | ||
|
||
func TestRepository_UpdateTokenLastUseTime(t *testing.T) { | ||
c := qt.New(t) | ||
tokenAccess := "fakeTokenAccess" | ||
|
||
mock, sqldb, repository, err := mockDBRepository() | ||
c.Assert(err, qt.IsNil) | ||
defer sqldb.Close() | ||
|
||
mock.ExpectBegin() | ||
mock.ExpectExec(regexp.QuoteMeta(`UPDATE "tokens" SET "last_use_time"=$1,"update_time"=$2 WHERE access_token = $3`)). | ||
WithArgs(sqlmock.AnyArg(), sqlmock.AnyArg(), tokenAccess). | ||
WillReturnResult(sqlmock.NewResult(1, 1)) | ||
|
||
mock.ExpectCommit() | ||
|
||
err = repository.UpdateTokenLastUseTime(context.Background(), tokenAccess) | ||
c.Assert(err, qt.IsNil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters