Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
jeff
pleroma
Commits
9d63b27d
Verified
Commit
9d63b27d
authored
6 years ago
by
href
Browse files
Options
Downloads
Patches
Plain Diff
Test FlakeID old id compat & Ecto type
parent
28d77e37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/flake_id.ex
+6
-0
6 additions, 0 deletions
lib/pleroma/flake_id.ex
test/flake_id_test.exs
+41
-0
41 additions, 0 deletions
test/flake_id_test.exs
with
47 additions
and
0 deletions
lib/pleroma/flake_id.ex
+
6
−
0
View file @
9d63b27d
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
FlakeId
do
@moduledoc
"""
Flake is a decentralized, k-ordered id generation service.
...
...
@@ -38,6 +42,8 @@ defmodule Pleroma.FlakeId do
def
from_string
(
unquote
(
Kernel
.
to_string
(
i
))),
do
:
<<
0
::
integer
-
size
(
128
)
>>
end
def
from_string
(
flake
=
<<
_
::
integer
-
size
(
128
)
>>
),
do
:
flake
def
from_string
(
string
)
when
is_binary
(
string
)
and
byte_size
(
string
)
<
18
do
case
Integer
.
parse
(
string
)
do
{
id
,
_
}
->
<<
0
::
integer
-
size
(
64
),
id
::
integer
-
size
(
64
)
>>
...
...
This diff is collapsed.
Click to expand it.
test/flake_id_test.exs
0 → 100644
+
41
−
0
View file @
9d63b27d
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
FlakeIdTest
do
use
Pleroma
.
DataCase
import
Kernel
,
except:
[
to_string:
1
]
import
Pleroma
.
FlakeId
describe
"fake flakes (compatibility with older serial integers)"
do
test
"from_string/1"
do
fake_flake
=
<<
0
::
integer
-
size
(
64
),
42
::
integer
-
size
(
64
)
>>
assert
from_string
(
"42"
)
==
fake_flake
end
test
"zero or -1 is a null flake"
do
fake_flake
=
<<
0
::
integer
-
size
(
128
)
>>
assert
from_string
(
"0"
)
==
fake_flake
assert
from_string
(
"-1"
)
==
fake_flake
end
test
"to_string/1"
do
fake_flake
=
<<
0
::
integer
-
size
(
64
),
42
::
integer
-
size
(
64
)
>>
assert
to_string
(
fake_flake
)
==
"42"
end
end
test
"ecto type behaviour"
do
flake
=
<<
0
,
0
,
1
,
104
,
80
,
229
,
2
,
235
,
140
,
22
,
69
,
201
,
53
,
210
,
0
,
0
>>
flake_s
=
"9eoozpwTul5mjSEDRI"
assert
cast
(
flake
)
==
{
:ok
,
flake_s
}
assert
cast
(
flake_s
)
==
{
:ok
,
flake_s
}
assert
load
(
flake
)
==
{
:ok
,
flake_s
}
assert
load
(
flake_s
)
==
{
:ok
,
flake_s
}
assert
dump
(
flake_s
)
==
{
:ok
,
flake
}
assert
dump
(
flake
)
==
{
:ok
,
flake
}
end
end
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