1
1
package backend
2
2
3
+ import com .scalableminds .util .accesscontext .TokenContext
3
4
import com .scalableminds .util .tools .Fox
4
5
import org .scalatestplus .play .PlaySpec
5
6
@@ -26,6 +27,8 @@ import scala.concurrent.ExecutionContext.{global => globalExecutionContext}
26
27
class DataVaultTestSuite extends PlaySpec {
27
28
28
29
val handleFoxJustification = " Handling Fox in Unit Test Context"
30
+ val emptyTokenContext : TokenContext = TokenContext (None )
31
+ val dummyDataStoreHost = " example.com"
29
32
30
33
" Data vault" when {
31
34
" using Range requests" when {
@@ -36,10 +39,11 @@ class DataVaultTestSuite extends PlaySpec {
36
39
" return correct response" in {
37
40
WsTestClient .withClient { ws =>
38
41
val uri = new URI (" http://storage.googleapis.com/" )
39
- val vaultPath = new VaultPath (uri, HttpsDataVault .create(RemoteSourceDescriptor (uri, None ), ws))
42
+ val vaultPath =
43
+ new VaultPath (uri, HttpsDataVault .create(RemoteSourceDescriptor (uri, None ), ws, dummyDataStoreHost))
40
44
val bytes =
41
45
(vaultPath / s " neuroglancer-fafb-data/fafb_v14/fafb_v14_orig/ $dataKey" )
42
- .readBytes(Some (range))(globalExecutionContext)
46
+ .readBytes(Some (range))(globalExecutionContext, emptyTokenContext )
43
47
.get(handleFoxJustification)
44
48
45
49
assert(bytes.length == range.length)
@@ -53,7 +57,9 @@ class DataVaultTestSuite extends PlaySpec {
53
57
val vaultPath = new VaultPath (uri, GoogleCloudDataVault .create(RemoteSourceDescriptor (uri, None )))
54
58
" return correct response" in {
55
59
56
- val bytes = (vaultPath / dataKey).readBytes(Some (range))(globalExecutionContext).get(handleFoxJustification)
60
+ val bytes = (vaultPath / dataKey)
61
+ .readBytes(Some (range))(globalExecutionContext, emptyTokenContext)
62
+ .get(handleFoxJustification)
57
63
58
64
assert(bytes.length == range.length)
59
65
assert(bytes.take(10 ).sameElements(Array (- 1 , - 40 , - 1 , - 32 , 0 , 16 , 74 , 70 , 73 , 70 )))
@@ -63,15 +69,15 @@ class DataVaultTestSuite extends PlaySpec {
63
69
" requesting a non-existent object" in {
64
70
val result =
65
71
(vaultPath / s " non-existent-key ${UUID .randomUUID}" )
66
- .readBytes()(globalExecutionContext)
72
+ .readBytes()(globalExecutionContext, emptyTokenContext )
67
73
.await(handleFoxJustification)
68
74
assertBoxEmpty(result)
69
75
}
70
76
}
71
77
" return failure" when {
72
78
" requesting invalid range" in {
73
79
val result = (vaultPath / dataKey)
74
- .readBytes(Some (Range .Long (- 5 , - 10 , 1 )))(globalExecutionContext)
80
+ .readBytes(Some (Range .Long (- 5 , - 10 , 1 )))(globalExecutionContext, emptyTokenContext )
75
81
.await(handleFoxJustification)
76
82
assertBoxFailure(result)
77
83
}
@@ -83,7 +89,7 @@ class DataVaultTestSuite extends PlaySpec {
83
89
uri,
84
90
Some (GoogleServiceAccountCredential (" name" , JsString (" secret" ), " user" , " org" )))))
85
91
val result = (vaultPath / dataKey)
86
- .readBytes(Some (Range .Long (- 10 , 10 , 1 )))(globalExecutionContext)
92
+ .readBytes(Some (Range .Long (- 10 , 10 , 1 )))(globalExecutionContext, emptyTokenContext )
87
93
.await(handleFoxJustification)
88
94
assertBoxFailure(result)
89
95
}
@@ -97,7 +103,9 @@ class DataVaultTestSuite extends PlaySpec {
97
103
val vaultPath =
98
104
new VaultPath (uri, S3DataVault .create(RemoteSourceDescriptor (uri, None ), ws)(globalExecutionContext))
99
105
val bytes =
100
- (vaultPath / " s0/5/5/5" ).readBytes(Some (range))(globalExecutionContext).get(handleFoxJustification)
106
+ (vaultPath / " s0/5/5/5" )
107
+ .readBytes(Some (range))(globalExecutionContext, emptyTokenContext)
108
+ .get(handleFoxJustification)
101
109
assert(bytes.length == range.length)
102
110
assert(bytes.take(10 ).sameElements(Array (0 , 0 , 0 , 3 , 0 , 0 , 0 , 64 , 0 , 0 )))
103
111
}
@@ -113,9 +121,10 @@ class DataVaultTestSuite extends PlaySpec {
113
121
" return correct response" in {
114
122
WsTestClient .withClient { ws =>
115
123
val uri = new URI (" http://storage.googleapis.com/" )
116
- val vaultPath = new VaultPath (uri, HttpsDataVault .create(RemoteSourceDescriptor (uri, None ), ws))
124
+ val vaultPath =
125
+ new VaultPath (uri, HttpsDataVault .create(RemoteSourceDescriptor (uri, None ), ws, dummyDataStoreHost))
117
126
val bytes = (vaultPath / s " neuroglancer-fafb-data/fafb_v14/fafb_v14_orig/ $dataKey" )
118
- .readBytes()(globalExecutionContext)
127
+ .readBytes()(globalExecutionContext, emptyTokenContext )
119
128
.get(handleFoxJustification)
120
129
121
130
assert(bytes.length == dataLength)
@@ -128,7 +137,8 @@ class DataVaultTestSuite extends PlaySpec {
128
137
" return correct response" in {
129
138
val uri = new URI (" gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_orig" )
130
139
val vaultPath = new VaultPath (uri, GoogleCloudDataVault .create(RemoteSourceDescriptor (uri, None )))
131
- val bytes = (vaultPath / dataKey).readBytes()(globalExecutionContext).get(handleFoxJustification)
140
+ val bytes =
141
+ (vaultPath / dataKey).readBytes()(globalExecutionContext, emptyTokenContext).get(handleFoxJustification)
132
142
133
143
assert(bytes.length == dataLength)
134
144
assert(bytes.take(10 ).sameElements(Array (- 1 , - 40 , - 1 , - 32 , 0 , 16 , 74 , 70 , 73 , 70 )))
@@ -143,7 +153,7 @@ class DataVaultTestSuite extends PlaySpec {
143
153
new VaultPath (uri, S3DataVault .create(RemoteSourceDescriptor (uri, None ), ws)(globalExecutionContext))
144
154
val bytes =
145
155
(vaultPath / " 33792-34304_29696-30208_3216-3232" )
146
- .readBytes()(globalExecutionContext)
156
+ .readBytes()(globalExecutionContext, emptyTokenContext )
147
157
.get(handleFoxJustification)
148
158
assert(bytes.take(10 ).sameElements(Array (- 87 , - 95 , - 85 , - 94 , - 101 , 124 , 115 , 100 , 113 , 111 )))
149
159
}
@@ -155,7 +165,8 @@ class DataVaultTestSuite extends PlaySpec {
155
165
WsTestClient .withClient { ws =>
156
166
val s3DataVault = S3DataVault .create(RemoteSourceDescriptor (uri, None ), ws)(globalExecutionContext)
157
167
val vaultPath = new VaultPath (uri, s3DataVault)
158
- val result = vaultPath.readBytes()(globalExecutionContext).await(handleFoxJustification)
168
+ val result =
169
+ vaultPath.readBytes()(globalExecutionContext, emptyTokenContext).await(handleFoxJustification)
159
170
assertBoxEmpty(result)
160
171
}
161
172
}
@@ -167,7 +178,8 @@ class DataVaultTestSuite extends PlaySpec {
167
178
WsTestClient .withClient { ws =>
168
179
val s3DataVault = S3DataVault .create(RemoteSourceDescriptor (uri, None ), ws)(globalExecutionContext)
169
180
val vaultPath = new VaultPath (uri, s3DataVault)
170
- val result = vaultPath.readBytes()(globalExecutionContext).await(handleFoxJustification)
181
+ val result =
182
+ vaultPath.readBytes()(globalExecutionContext, emptyTokenContext).await(handleFoxJustification)
171
183
assertBoxEmpty(result)
172
184
}
173
185
}
@@ -207,7 +219,8 @@ class DataVaultTestSuite extends PlaySpec {
207
219
" using vault path" when {
208
220
class MockDataVault extends DataVault {
209
221
override def readBytesAndEncoding (path : VaultPath , range : RangeSpecifier )(
210
- implicit ec : ExecutionContext ): Fox [(Array [Byte ], Encoding .Value )] = ???
222
+ implicit ec : ExecutionContext ,
223
+ tc : TokenContext ): Fox [(Array [Byte ], Encoding .Value )] = ???
211
224
212
225
override def listDirectory (path : VaultPath ,
213
226
maxItems : Int )(implicit ec : ExecutionContext ): Fox [List [VaultPath ]] = ???
0 commit comments