Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
8251db7e
Commit
8251db7e
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix nickname saving bug
parent
fe87f3ae
No related branches found
No related tags found
4 merge requests
!510
Release
,
!419
rewrote the health tracker to both consider if there are waiting rounds and...
,
!397
Fully Decentralized channels
,
!340
Project/channels
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
channels/nickname.go
+5
-5
5 additions, 5 deletions
channels/nickname.go
channels/nickname_test.go
+30
-0
30 additions, 0 deletions
channels/nickname_test.go
with
35 additions
and
5 deletions
channels/nickname.go
+
5
−
5
View file @
8251db7e
...
@@ -77,8 +77,8 @@ func (nm *nicknameManager) DeleteNickname(ch *id.ID) error {
...
@@ -77,8 +77,8 @@ func (nm *nicknameManager) DeleteNickname(ch *id.ID) error {
// channelIDToNickname is a serialization structure. This is used by the save
// channelIDToNickname is a serialization structure. This is used by the save
// and load functions to serialize the nicknameManager's byChannel map.
// and load functions to serialize the nicknameManager's byChannel map.
type
channelIDToNickname
struct
{
type
channelIDToNickname
struct
{
c
hannelId
id
.
ID
C
hannelId
id
.
ID
n
ickname
string
N
ickname
string
}
}
// save stores the nickname manager to disk. The caller of this must
// save stores the nickname manager to disk. The caller of this must
...
@@ -87,8 +87,8 @@ func (nm *nicknameManager) save() error {
...
@@ -87,8 +87,8 @@ func (nm *nicknameManager) save() error {
list
:=
make
([]
channelIDToNickname
,
0
)
list
:=
make
([]
channelIDToNickname
,
0
)
for
chId
,
nickname
:=
range
nm
.
byChannel
{
for
chId
,
nickname
:=
range
nm
.
byChannel
{
list
=
append
(
list
,
channelIDToNickname
{
list
=
append
(
list
,
channelIDToNickname
{
c
hannelId
:
chId
,
C
hannelId
:
chId
,
n
ickname
:
nickname
,
N
ickname
:
nickname
,
})
})
}
}
...
@@ -120,7 +120,7 @@ func (nm *nicknameManager) load() error {
...
@@ -120,7 +120,7 @@ func (nm *nicknameManager) load() error {
for
i
:=
range
list
{
for
i
:=
range
list
{
current
:=
list
[
i
]
current
:=
list
[
i
]
nm
.
byChannel
[
current
.
c
hannelId
]
=
current
.
n
ickname
nm
.
byChannel
[
current
.
C
hannelId
]
=
current
.
N
ickname
}
}
return
nil
return
nil
...
...
This diff is collapsed.
Click to expand it.
channels/nickname_test.go
+
30
−
0
View file @
8251db7e
...
@@ -29,7 +29,37 @@ func TestNicknameManager_SetGetNickname(t *testing.T) {
...
@@ -29,7 +29,37 @@ func TestNicknameManager_SetGetNickname(t *testing.T) {
"
\n
Received: %s"
,
nickname
,
received
)
"
\n
Received: %s"
,
nickname
,
received
)
}
}
}
}
}
// Unit test. Tests that once you set a nickname with SetNickname, you can
// retrieve the nickname using GetNickname after a reload.
func
TestNicknameManager_SetGetNickname_Reload
(
t
*
testing
.
T
)
{
kv
:=
versioned
.
NewKV
(
ekv
.
MakeMemstore
())
nm
:=
loadOrNewNicknameManager
(
kv
)
for
i
:=
0
;
i
<
numTests
;
i
++
{
chId
:=
id
.
NewIdFromUInt
(
uint64
(
i
),
id
.
User
,
t
)
nickname
:=
"nickname#"
+
strconv
.
Itoa
(
i
)
err
:=
nm
.
SetNickname
(
nickname
,
chId
)
if
err
!=
nil
{
t
.
Fatalf
(
"SetNickname error when setting %s: %+v"
,
nickname
,
err
)
}
}
nm2
:=
loadOrNewNicknameManager
(
kv
)
for
i
:=
0
;
i
<
numTests
;
i
++
{
chId
:=
id
.
NewIdFromUInt
(
uint64
(
i
),
id
.
User
,
t
)
// nickname := "nickname#" + strconv.Itoa(i)
nick
,
exists
:=
nm2
.
GetNickname
(
chId
)
if
!
exists
{
t
.
Fatalf
(
"Nickname %d not found "
,
i
)
}
expected
:=
"nickname#"
+
strconv
.
Itoa
(
i
)
if
nick
!=
expected
{
t
.
Fatalf
(
"Nickname %d not found, expected: %s, received: %s "
,
i
,
expected
,
nick
)
}
}
}
}
// Error case: Tests that nicknameManager.GetNickname returns a false boolean
// Error case: Tests that nicknameManager.GetNickname returns a false boolean
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment