Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
xxdk-wasm
Commits
53f8a417
Commit
53f8a417
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added unit test for indexeddb uniquenes
parent
54364082
No related branches found
No related tags found
1 merge request
!60
Revert "Fail a test to be sure it works"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexedDb/implementation_test.go
+53
-0
53 additions, 0 deletions
indexedDb/implementation_test.go
with
53 additions
and
0 deletions
indexedDb/implementation_test.go
+
53
−
0
View file @
53f8a417
...
@@ -12,6 +12,7 @@ package indexedDb
...
@@ -12,6 +12,7 @@ package indexedDb
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/hack-pad/go-indexeddb/idb"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/netTime"
"os"
"os"
...
@@ -252,3 +253,55 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
...
@@ -252,3 +253,55 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
t
.
Errorf
(
"Expected %d messages, got %d"
,
expectedMessages
,
len
(
result
))
t
.
Errorf
(
"Expected %d messages, got %d"
,
expectedMessages
,
len
(
result
))
}
}
}
}
// This test is designed to prove the behavior of unique indexes.
// Inserts will not fail, they simply will not happen.
func
TestWasmModel_receiveHelper_UniqueIndex
(
t
*
testing
.
T
)
{
testString
:=
"test_receiveHelper_UniqueIndex"
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Ensure index is unique
txn
,
err
:=
eventModel
.
db
.
Transaction
(
idb
.
TransactionReadOnly
,
messageStoreName
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
store
,
err
:=
txn
.
ObjectStore
(
messageStoreName
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
idx
,
err
:=
store
.
Index
(
messageStoreMessageIndex
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
isUnique
,
err
:=
idx
.
Unique
();
!
isUnique
{
t
.
Fatalf
(
"Index is not unique!"
)
}
else
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// First message insert should succeed
testMsgId
:=
channel
.
MakeMessageID
([]
byte
(
testString
),
&
id
.
ID
{
1
})
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testString
,
testString
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
channels
.
Sent
)
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The duplicate entry won't fail, it just silently shouldn't happen
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
results
,
err
:=
eventModel
.
dump
(
messageStoreName
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
if
len
(
results
)
!=
1
{
t
.
Fatalf
(
"Expected only a single message, got %d"
,
len
(
results
))
}
}
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