@@ -6,6 +6,8 @@ import Bilge.Assert
6
6
import CargoHold.API.V3 (randToken )
7
7
import Conduit
8
8
import Control.Lens
9
+ import Crypto.Random
10
+ import qualified Data.ByteString as BS
9
11
import Data.Id
10
12
import Data.Qualified
11
13
import Data.UUID.V4
@@ -118,14 +120,17 @@ testGetAssetWrongToken c = do
118
120
testLargeAsset :: TestSignature ()
119
121
testLargeAsset c = do
120
122
-- Initial upload
121
- let size = 1024 * 1024
122
- settings =
123
+ let settings =
123
124
defAssetSettings
124
125
& set setAssetRetention (Just AssetVolatile )
125
126
uid <- liftIO $ Id <$> nextRandom
127
+ -- generate random bytes
128
+ let size = 1024 * 1024
129
+ bs <- liftIO $ getRandomBytes size
130
+
126
131
ast :: Asset <-
127
132
responseJsonError
128
- =<< uploadRandom (c . path " /assets/v3" ) uid settings applicationOctetStream size
133
+ =<< uploadSimple (c . path " /assets/v3" ) uid settings ( applicationOctetStream, bs)
129
134
<!! const 201 === statusCode
130
135
131
136
-- Call get-asset federation API
@@ -137,11 +142,20 @@ testLargeAsset c = do
137
142
gaToken = tok,
138
143
gaKey = qUnqualified key
139
144
}
145
+ let getAllChunks getChunk = fmap reverse . ($ [] ) . fix $ \ go acc -> do
146
+ chunk <- getChunk
147
+ if BS. null chunk
148
+ then pure acc
149
+ else go (chunk : acc)
150
+
140
151
http empty (method HTTP. POST . c . path " /federation/stream-asset" . json ga) $ \ resp -> do
141
152
statusCode resp @?= 200
142
- -- check that the first chunk is received
143
- chunk <- responseBody resp
144
- print chunk
153
+ chunks <- getAllChunks (responseBody resp)
154
+ let minNumChunks = 8
155
+ assertBool
156
+ (" Expected at least " <> show minNumChunks <> " chunks, got " <> show (length chunks))
157
+ (length chunks > minNumChunks)
158
+ mconcat chunks @?= bs
145
159
146
160
testStreamAsset :: TestSignature ()
147
161
testStreamAsset c = do
@@ -165,9 +179,9 @@ testStreamAsset c = do
165
179
gaToken = tok,
166
180
gaKey = qUnqualified key
167
181
}
168
- respBody <- fmap responseBody $
169
- post (c . path " /federation/stream-asset " . json ga)
170
- <!! const 200 === statusCode
171
-
182
+ respBody <-
183
+ fmap responseBody $
184
+ post (c . path " /federation/stream-asset " . json ga)
185
+ <!! const 200 === statusCode
172
186
173
187
liftIO $ respBody @?= Just " Hello World"
0 commit comments