Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
8f24d239
Commit
8f24d239
authored
Jan 08, 2026
by
Edric Li
Browse files
fix: update integration tests for GatewayCache groupID parameter
parent
b7a29a4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/repository/gateway_cache_integration_test.go
View file @
8f24d239
...
@@ -24,18 +24,19 @@ func (s *GatewayCacheSuite) SetupTest() {
...
@@ -24,18 +24,19 @@ func (s *GatewayCacheSuite) SetupTest() {
}
}
func
(
s
*
GatewayCacheSuite
)
TestGetSessionAccountID_Missing
()
{
func
(
s
*
GatewayCacheSuite
)
TestGetSessionAccountID_Missing
()
{
_
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
"nonexistent"
)
_
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
1
,
"nonexistent"
)
require
.
True
(
s
.
T
(),
errors
.
Is
(
err
,
redis
.
Nil
),
"expected redis.Nil for missing session"
)
require
.
True
(
s
.
T
(),
errors
.
Is
(
err
,
redis
.
Nil
),
"expected redis.Nil for missing session"
)
}
}
func
(
s
*
GatewayCacheSuite
)
TestSetAndGetSessionAccountID
()
{
func
(
s
*
GatewayCacheSuite
)
TestSetAndGetSessionAccountID
()
{
sessionID
:=
"s1"
sessionID
:=
"s1"
accountID
:=
int64
(
99
)
accountID
:=
int64
(
99
)
groupID
:=
int64
(
1
)
sessionTTL
:=
1
*
time
.
Minute
sessionTTL
:=
1
*
time
.
Minute
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
sessionID
,
accountID
,
sessionTTL
),
"SetSessionAccountID"
)
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
groupID
,
sessionID
,
accountID
,
sessionTTL
),
"SetSessionAccountID"
)
sid
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
sessionID
)
sid
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
groupID
,
sessionID
)
require
.
NoError
(
s
.
T
(),
err
,
"GetSessionAccountID"
)
require
.
NoError
(
s
.
T
(),
err
,
"GetSessionAccountID"
)
require
.
Equal
(
s
.
T
(),
accountID
,
sid
,
"session id mismatch"
)
require
.
Equal
(
s
.
T
(),
accountID
,
sid
,
"session id mismatch"
)
}
}
...
@@ -43,11 +44,12 @@ func (s *GatewayCacheSuite) TestSetAndGetSessionAccountID() {
...
@@ -43,11 +44,12 @@ func (s *GatewayCacheSuite) TestSetAndGetSessionAccountID() {
func
(
s
*
GatewayCacheSuite
)
TestSessionAccountID_TTL
()
{
func
(
s
*
GatewayCacheSuite
)
TestSessionAccountID_TTL
()
{
sessionID
:=
"s2"
sessionID
:=
"s2"
accountID
:=
int64
(
100
)
accountID
:=
int64
(
100
)
groupID
:=
int64
(
1
)
sessionTTL
:=
1
*
time
.
Minute
sessionTTL
:=
1
*
time
.
Minute
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
sessionID
,
accountID
,
sessionTTL
),
"SetSessionAccountID"
)
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
groupID
,
sessionID
,
accountID
,
sessionTTL
),
"SetSessionAccountID"
)
sessionKey
:=
sticky
Session
Prefix
+
sessionID
sessionKey
:=
build
Session
Key
(
groupID
,
sessionID
)
ttl
,
err
:=
s
.
rdb
.
TTL
(
s
.
ctx
,
sessionKey
)
.
Result
()
ttl
,
err
:=
s
.
rdb
.
TTL
(
s
.
ctx
,
sessionKey
)
.
Result
()
require
.
NoError
(
s
.
T
(),
err
,
"TTL sessionKey after Set"
)
require
.
NoError
(
s
.
T
(),
err
,
"TTL sessionKey after Set"
)
s
.
AssertTTLWithin
(
ttl
,
1
*
time
.
Second
,
sessionTTL
)
s
.
AssertTTLWithin
(
ttl
,
1
*
time
.
Second
,
sessionTTL
)
...
@@ -56,14 +58,15 @@ func (s *GatewayCacheSuite) TestSessionAccountID_TTL() {
...
@@ -56,14 +58,15 @@ func (s *GatewayCacheSuite) TestSessionAccountID_TTL() {
func
(
s
*
GatewayCacheSuite
)
TestRefreshSessionTTL
()
{
func
(
s
*
GatewayCacheSuite
)
TestRefreshSessionTTL
()
{
sessionID
:=
"s3"
sessionID
:=
"s3"
accountID
:=
int64
(
101
)
accountID
:=
int64
(
101
)
groupID
:=
int64
(
1
)
initialTTL
:=
1
*
time
.
Minute
initialTTL
:=
1
*
time
.
Minute
refreshTTL
:=
3
*
time
.
Minute
refreshTTL
:=
3
*
time
.
Minute
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
sessionID
,
accountID
,
initialTTL
),
"SetSessionAccountID"
)
require
.
NoError
(
s
.
T
(),
s
.
cache
.
SetSessionAccountID
(
s
.
ctx
,
groupID
,
sessionID
,
accountID
,
initialTTL
),
"SetSessionAccountID"
)
require
.
NoError
(
s
.
T
(),
s
.
cache
.
RefreshSessionTTL
(
s
.
ctx
,
sessionID
,
refreshTTL
),
"RefreshSessionTTL"
)
require
.
NoError
(
s
.
T
(),
s
.
cache
.
RefreshSessionTTL
(
s
.
ctx
,
groupID
,
sessionID
,
refreshTTL
),
"RefreshSessionTTL"
)
sessionKey
:=
sticky
Session
Prefix
+
sessionID
sessionKey
:=
build
Session
Key
(
groupID
,
sessionID
)
ttl
,
err
:=
s
.
rdb
.
TTL
(
s
.
ctx
,
sessionKey
)
.
Result
()
ttl
,
err
:=
s
.
rdb
.
TTL
(
s
.
ctx
,
sessionKey
)
.
Result
()
require
.
NoError
(
s
.
T
(),
err
,
"TTL after Refresh"
)
require
.
NoError
(
s
.
T
(),
err
,
"TTL after Refresh"
)
s
.
AssertTTLWithin
(
ttl
,
1
*
time
.
Second
,
refreshTTL
)
s
.
AssertTTLWithin
(
ttl
,
1
*
time
.
Second
,
refreshTTL
)
...
@@ -71,18 +74,19 @@ func (s *GatewayCacheSuite) TestRefreshSessionTTL() {
...
@@ -71,18 +74,19 @@ func (s *GatewayCacheSuite) TestRefreshSessionTTL() {
func
(
s
*
GatewayCacheSuite
)
TestRefreshSessionTTL_MissingKey
()
{
func
(
s
*
GatewayCacheSuite
)
TestRefreshSessionTTL_MissingKey
()
{
// RefreshSessionTTL on a missing key should not error (no-op)
// RefreshSessionTTL on a missing key should not error (no-op)
err
:=
s
.
cache
.
RefreshSessionTTL
(
s
.
ctx
,
"missing-session"
,
1
*
time
.
Minute
)
err
:=
s
.
cache
.
RefreshSessionTTL
(
s
.
ctx
,
1
,
"missing-session"
,
1
*
time
.
Minute
)
require
.
NoError
(
s
.
T
(),
err
,
"RefreshSessionTTL on missing key should not error"
)
require
.
NoError
(
s
.
T
(),
err
,
"RefreshSessionTTL on missing key should not error"
)
}
}
func
(
s
*
GatewayCacheSuite
)
TestGetSessionAccountID_CorruptedValue
()
{
func
(
s
*
GatewayCacheSuite
)
TestGetSessionAccountID_CorruptedValue
()
{
sessionID
:=
"corrupted"
sessionID
:=
"corrupted"
sessionKey
:=
stickySessionPrefix
+
sessionID
groupID
:=
int64
(
1
)
sessionKey
:=
buildSessionKey
(
groupID
,
sessionID
)
// Set a non-integer value
// Set a non-integer value
require
.
NoError
(
s
.
T
(),
s
.
rdb
.
Set
(
s
.
ctx
,
sessionKey
,
"not-a-number"
,
1
*
time
.
Minute
)
.
Err
(),
"Set invalid value"
)
require
.
NoError
(
s
.
T
(),
s
.
rdb
.
Set
(
s
.
ctx
,
sessionKey
,
"not-a-number"
,
1
*
time
.
Minute
)
.
Err
(),
"Set invalid value"
)
_
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
sessionID
)
_
,
err
:=
s
.
cache
.
GetSessionAccountID
(
s
.
ctx
,
groupID
,
sessionID
)
require
.
Error
(
s
.
T
(),
err
,
"expected error for corrupted value"
)
require
.
Error
(
s
.
T
(),
err
,
"expected error for corrupted value"
)
require
.
False
(
s
.
T
(),
errors
.
Is
(
err
,
redis
.
Nil
),
"expected parsing error, not redis.Nil"
)
require
.
False
(
s
.
T
(),
errors
.
Is
(
err
,
redis
.
Nil
),
"expected parsing error, not redis.Nil"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment