Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
cache
Commits
b868e423
Commit
b868e423
authored
Jan 26, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test code
parent
8c62bdfa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
2 deletions
+131
-2
cache_test.go
cachedata/cache_test.go
+129
-0
db.go
model/db.go
+2
-2
No files found.
cachedata/cache_test.go
0 → 100644
View file @
b868e423
package
cachedata
import
(
"context"
"github.com/odysseus/payment/model"
"testing"
)
var
(
_cache
*
CacheData
)
func
newCache
()
*
CacheData
{
if
_cache
!=
nil
{
return
_cache
}
_cache
=
NewCacheData
(
context
.
Background
(),
RedisConnParam
{
Addr
:
"127.0.0.1:6739"
,
Password
:
"123456"
,
DbIndex
:
0
,
},
model
.
DbConfig
{
Host
:
"127.0.0.1"
,
Port
:
3306
,
DbName
:
"backend"
,
Passwd
:
"123456"
,
})
return
_cache
}
func
TestCacheData_Query
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testPath
:=
""
testUid
:=
int64
(
1
)
task
,
err
:=
cache
.
Query
(
testPath
,
testUid
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
t
.
Log
(
task
)
}
func
TestCacheData_MQuery
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testPaths
:=
[]
string
{
"path1"
,
"path2"
,
"path3"
,
}
testUids
:=
[]
int64
{
1
,
2
,
3
,
}
taskChan
,
err
:=
cache
.
MQuery
(
testPaths
,
testUids
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
count
:=
0
for
task
:=
range
taskChan
{
count
++
t
.
Log
(
task
)
if
count
==
len
(
testPaths
)
{
break
}
}
}
func
TestCacheData_SetUserInfo
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
1
)
user
,
err
:=
cache
.
GetUserInfo
(
testUid
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
t
.
Log
(
user
)
}
func
TestCacheData_UpdateUserBalance
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
1
)
testBalance
:=
100
err
:=
cache
.
UpdateUserBalance
(
testUid
,
testBalance
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestCacheData_UpdateUserLevel
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
1
)
testLevel
:=
1
err
:=
cache
.
UpdateUserLevel
(
testUid
,
testLevel
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestCacheData_UpdateUserDeleted
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
1
)
testDeleted
:=
1
err
:=
cache
.
UpdateUserDeleted
(
testUid
,
testDeleted
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestCacheData_UpdateUserBalanceAndLevel
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
1
)
testBalance
:=
100
testLevel
:=
1
// update balance first
err
:=
cache
.
UpdateUserBalance
(
testUid
,
testBalance
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
// update level second.
err
=
cache
.
UpdateUserLevel
(
testUid
,
testLevel
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
model/db.go
View file @
b868e423
...
@@ -10,13 +10,13 @@ type DbConfig struct {
...
@@ -10,13 +10,13 @@ type DbConfig struct {
User
string
User
string
Passwd
string
Passwd
string
Host
string
Host
string
Port
string
Port
int
DbName
string
DbName
string
}
}
func
DbInit
(
dbconf
DbConfig
)
{
func
DbInit
(
dbconf
DbConfig
)
{
// Set up database
// Set up database
datasource
:=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%
s
)/%s?charset=utf8"
,
dbconf
.
User
,
dbconf
.
Passwd
,
dbconf
.
Host
,
dbconf
.
Port
,
dbconf
.
DbName
)
datasource
:=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%
d
)/%s?charset=utf8"
,
dbconf
.
User
,
dbconf
.
Passwd
,
dbconf
.
Host
,
dbconf
.
Port
,
dbconf
.
DbName
)
orm
.
RegisterDriver
(
"mysql"
,
orm
.
DRMySQL
)
orm
.
RegisterDriver
(
"mysql"
,
orm
.
DRMySQL
)
err
:=
orm
.
RegisterDataBase
(
"default"
,
"mysql"
,
datasource
)
err
:=
orm
.
RegisterDataBase
(
"default"
,
"mysql"
,
datasource
)
if
err
!=
nil
{
if
err
!=
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