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
245a94ff
Commit
245a94ff
authored
4 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/fixUpgrade' into fixUpgrade
parents
80edec44
8b66cbd2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
storage/versioned/kv_test.go
+88
-4
88 additions, 4 deletions
storage/versioned/kv_test.go
with
88 additions
and
4 deletions
storage/versioned/kv_test.go
+
88
−
4
View file @
245a94ff
...
...
@@ -9,9 +9,11 @@ package versioned
import
(
"bytes"
"
gitlab.com/elixxir/ekv
"
"
errors
"
"testing"
"time"
"gitlab.com/elixxir/ekv"
)
// KV Get should call the Upgrade function when it's available
...
...
@@ -30,8 +32,8 @@ func TestVersionedKV_Get_Err(t *testing.T) {
}
}
// Test versioned KV
Upgrade
path
func
TestVersionedKV_Get
_
Upgrade
(
t
*
testing
.
T
)
{
// Test versioned KV
happy
path
func
TestVersionedKV_GetUpgrade
(
t
*
testing
.
T
)
{
// Set up a dummy KV with the required data
kv
:=
make
(
ekv
.
Memstore
)
vkv
:=
NewKV
(
kv
)
...
...
@@ -44,7 +46,15 @@ func TestVersionedKV_Get_Upgrade(t *testing.T) {
originalSerialized
:=
original
.
Marshal
()
kv
[
key
]
=
originalSerialized
result
,
err
:=
vkv
.
Get
(
key
)
upgrade
:=
[]
Upgrade
{
func
(
oldObject
*
Object
)
(
*
Object
,
error
)
{
return
&
Object
{
Version
:
1
,
Timestamp
:
time
.
Now
(),
Data
:
[]
byte
(
"this object was upgraded from v0 to v1"
),
},
nil
}}
result
,
err
:=
vkv
.
GetUpgrade
(
key
,
upgrade
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error getting something that should have been in: %v"
,
err
)
...
...
@@ -56,6 +66,80 @@ func TestVersionedKV_Get_Upgrade(t *testing.T) {
}
}
// Test versioned KV key not found path
func
TestVersionedKV_GetUpgrade_KeyNotFound
(
t
*
testing
.
T
)
{
// Set up a dummy KV with the required data
kv
:=
make
(
ekv
.
Memstore
)
vkv
:=
NewKV
(
kv
)
key
:=
MakeKeyWithPrefix
(
"test"
,
"12345"
)
upgrade
:=
[]
Upgrade
{
func
(
oldObject
*
Object
)
(
*
Object
,
error
)
{
return
&
Object
{
Version
:
1
,
Timestamp
:
time
.
Now
(),
Data
:
[]
byte
(
"this object was upgraded from v0 to v1"
),
},
nil
}}
_
,
err
:=
vkv
.
GetUpgrade
(
key
,
upgrade
)
if
err
==
nil
{
t
.
Fatalf
(
"Error getting something that should have been in: %v"
,
err
)
}
}
// Test versioned KV upgrade func returns error path
func
TestVersionedKV_GetUpgrade_UpgradeReturnsError
(
t
*
testing
.
T
)
{
// Set up a dummy KV with the required data
kv
:=
make
(
ekv
.
Memstore
)
vkv
:=
NewKV
(
kv
)
key
:=
MakeKeyWithPrefix
(
"test"
,
"12345"
)
original
:=
Object
{
Version
:
0
,
Timestamp
:
time
.
Now
(),
Data
:
[]
byte
(
"not upgraded"
),
}
originalSerialized
:=
original
.
Marshal
()
kv
[
key
]
=
originalSerialized
upgrade
:=
[]
Upgrade
{
func
(
oldObject
*
Object
)
(
*
Object
,
error
)
{
return
&
Object
{},
errors
.
New
(
"test error"
)
}}
defer
func
()
{
if
r
:=
recover
();
r
==
nil
{
t
.
Errorf
(
"The code did not panic"
)
}
}()
_
,
_
=
vkv
.
GetUpgrade
(
key
,
upgrade
)
}
// Test delete key happy path
func
TestVersionedKV_Delete
(
t
*
testing
.
T
)
{
// Set up a dummy KV with the required data
kv
:=
make
(
ekv
.
Memstore
)
vkv
:=
NewKV
(
kv
)
key
:=
MakeKeyWithPrefix
(
"test"
,
"12345"
)
original
:=
Object
{
Version
:
0
,
Timestamp
:
time
.
Now
(),
Data
:
[]
byte
(
"not upgraded"
),
}
originalSerialized
:=
original
.
Marshal
()
kv
[
key
]
=
originalSerialized
err
:=
vkv
.
Delete
(
key
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error getting something that should have been in: %v"
,
err
)
}
if
_
,
ok
:=
kv
[
key
];
ok
{
t
.
Fatal
(
"Key still exists in kv map"
)
}
}
// Test Get without Upgrade path
func
TestVersionedKV_Get
(
t
*
testing
.
T
)
{
// Set up a dummy KV with the required data
...
...
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