Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
mobile
iOS
Elixxir dApps SDK Swift
Commits
7b722418
Commit
7b722418
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add BackupStorage.stored function
parent
c15b6a04
No related branches found
No related tags found
2 merge requests
!111
XXMessengerClient.BackupStorage improvements
,
!102
Release 1.0.0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/XXMessengerClient/Utils/BackupStorage.swift
+5
-1
5 additions, 1 deletion
Sources/XXMessengerClient/Utils/BackupStorage.swift
Tests/XXMessengerClientTests/Utils/BackupStorageTests.swift
+18
-11
18 additions, 11 deletions
Tests/XXMessengerClientTests/Utils/BackupStorageTests.swift
with
23 additions
and
12 deletions
Sources/XXMessengerClient/Utils/BackupStorage.swift
+
5
−
1
View file @
7b722418
...
@@ -18,6 +18,7 @@ public struct BackupStorage {
...
@@ -18,6 +18,7 @@ public struct BackupStorage {
public
typealias
Observer
=
(
Backup
?)
->
Void
public
typealias
Observer
=
(
Backup
?)
->
Void
public
var
stored
:
()
->
Backup
?
public
var
store
:
(
Data
)
throws
->
Void
public
var
store
:
(
Data
)
throws
->
Void
public
var
observe
:
(
@escaping
Observer
)
->
Cancellable
public
var
observe
:
(
@escaping
Observer
)
->
Cancellable
public
var
remove
:
()
throws
->
Void
public
var
remove
:
()
throws
->
Void
...
@@ -43,6 +44,9 @@ extension BackupStorage {
...
@@ -43,6 +44,9 @@ extension BackupStorage {
backup
=
Backup
(
date
:
fileDate
,
data
:
fileData
)
backup
=
Backup
(
date
:
fileDate
,
data
:
fileData
)
}
}
return
BackupStorage
(
return
BackupStorage
(
stored
:
{
backup
},
store
:
{
data
in
store
:
{
data
in
let
newBackup
=
Backup
(
let
newBackup
=
Backup
(
date
:
now
(),
date
:
now
(),
...
@@ -55,7 +59,6 @@ extension BackupStorage {
...
@@ -55,7 +59,6 @@ extension BackupStorage {
observe
:
{
observer
in
observe
:
{
observer
in
let
id
=
UUID
()
let
id
=
UUID
()
observers
[
id
]
=
observer
observers
[
id
]
=
observer
defer
{
observers
[
id
]?(
backup
)
}
return
Cancellable
{
return
Cancellable
{
observers
[
id
]
=
nil
observers
[
id
]
=
nil
}
}
...
@@ -71,6 +74,7 @@ extension BackupStorage {
...
@@ -71,6 +74,7 @@ extension BackupStorage {
extension
BackupStorage
{
extension
BackupStorage
{
public
static
let
unimplemented
=
BackupStorage
(
public
static
let
unimplemented
=
BackupStorage
(
stored
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.stored"
),
store
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.store"
),
store
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.store"
),
observe
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.observe"
,
placeholder
:
Cancellable
{}),
observe
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.observe"
,
placeholder
:
Cancellable
{}),
remove
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.remove"
)
remove
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.remove"
)
...
...
This diff is collapsed.
Click to expand it.
Tests/XXMessengerClientTests/Utils/BackupStorageTests.swift
+
18
−
11
View file @
7b722418
...
@@ -32,6 +32,10 @@ final class BackupStorageTests: XCTestCase {
...
@@ -32,6 +32,10 @@ final class BackupStorageTests: XCTestCase {
path
:
path
path
:
path
)
)
XCTAssertNoDifference
(
storage
.
stored
(),
BackupStorage
.
Backup
(
date
:
fileDate
,
data
:
fileData
)
)
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[
.
didLoadFile
(
path
),
.
didLoadFile
(
path
),
.
didGetModifiedTime
(
path
),
.
didGetModifiedTime
(
path
),
...
@@ -42,43 +46,46 @@ final class BackupStorageTests: XCTestCase {
...
@@ -42,43 +46,46 @@ final class BackupStorageTests: XCTestCase {
actions
.
append
(
.
didObserve
(
"A"
,
backup
))
actions
.
append
(
.
didObserve
(
"A"
,
backup
))
}
}
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[])
.
didObserve
(
"A"
,
.
init
(
date
:
fileDate
,
data
:
fileData
))
XCTAssertNoDifference
(
])
storage
.
stored
(),
BackupStorage
.
Backup
(
date
:
fileDate
,
data
:
fileData
)
)
actions
=
[]
actions
=
[]
now
=
.
init
(
1
)
now
=
.
init
(
1
)
let
data1
=
"data-1"
.
data
(
using
:
.
utf8
)
!
let
data1
=
"data-1"
.
data
(
using
:
.
utf8
)
!
try
storage
.
store
(
data1
)
try
storage
.
store
(
data1
)
XCTAssertNoDifference
(
storage
.
stored
(),
BackupStorage
.
Backup
(
date
:
.
init
(
1
),
data
:
data1
)
)
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[
.
didObserve
(
"A"
,
.
init
(
date
:
.
init
(
1
),
data
:
data1
)),
.
didObserve
(
"A"
,
.
init
(
date
:
.
init
(
1
),
data
:
data1
)),
.
didSaveFile
(
path
,
data1
),
.
didSaveFile
(
path
,
data1
),
])
])
actions
=
[]
actions
=
[]
now
=
.
init
(
2
)
let
observerB
=
storage
.
observe
{
backup
in
let
observerB
=
storage
.
observe
{
backup
in
actions
.
append
(
.
didObserve
(
"B"
,
backup
))
actions
.
append
(
.
didObserve
(
"B"
,
backup
))
}
}
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[])
.
didObserve
(
"B"
,
.
init
(
date
:
.
init
(
1
),
data
:
data1
))
])
actions
=
[]
actions
=
[]
now
=
.
init
(
3
)
now
=
.
init
(
2
)
observerA
.
cancel
()
observerA
.
cancel
()
let
data2
=
"data-2"
.
data
(
using
:
.
utf8
)
!
let
data2
=
"data-2"
.
data
(
using
:
.
utf8
)
!
try
storage
.
store
(
data2
)
try
storage
.
store
(
data2
)
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[
.
didObserve
(
"B"
,
.
init
(
date
:
.
init
(
3
),
data
:
data2
)),
.
didObserve
(
"B"
,
.
init
(
date
:
.
init
(
2
),
data
:
data2
)),
.
didSaveFile
(
path
,
data2
),
.
didSaveFile
(
path
,
data2
),
])
])
actions
=
[]
actions
=
[]
now
=
.
init
(
4
)
now
=
.
init
(
3
)
try
storage
.
remove
()
try
storage
.
remove
()
XCTAssertNoDifference
(
actions
,
[
XCTAssertNoDifference
(
actions
,
[
...
@@ -87,7 +94,7 @@ final class BackupStorageTests: XCTestCase {
...
@@ -87,7 +94,7 @@ final class BackupStorageTests: XCTestCase {
])
])
actions
=
[]
actions
=
[]
now
=
.
init
(
5
)
now
=
.
init
(
4
)
observerB
.
cancel
()
observerB
.
cancel
()
let
data3
=
"data-3"
.
data
(
using
:
.
utf8
)
!
let
data3
=
"data-3"
.
data
(
using
:
.
utf8
)
!
try
storage
.
store
(
data3
)
try
storage
.
store
(
data3
)
...
...
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