...
1description: "poc-gridfs"
2
3schemaVersion: "1.0"
4
5createEntities:
6 - client:
7 id: &client0 client0
8 - database:
9 id: &database0 database0
10 client: *client0
11 databaseName: &database0Name gridfs-tests
12 - bucket:
13 id: &bucket0 bucket0
14 database: *database0
15 - collection:
16 id: &bucket0_files_collection bucket0_files_collection
17 database: *database0
18 collectionName: &bucket0_files_collectionName fs.files
19 - collection:
20 id: &bucket0_chunks_collection bucket0_chunks_collection
21 database: *database0
22 collectionName: &bucket0_chunks_collectionName fs.chunks
23
24initialData:
25 - collectionName: *bucket0_files_collectionName
26 databaseName: *database0Name
27 documents:
28 - _id: { $oid: "000000000000000000000005" }
29 length: 10
30 chunkSize: 4
31 uploadDate: { $date: "1970-01-01T00:00:00.000Z" }
32 md5: "57d83cd477bfb1ccd975ab33d827a92b"
33 filename: "length-10"
34 contentType: "application/octet-stream"
35 aliases: []
36 metadata: {}
37 - collectionName: *bucket0_chunks_collectionName
38 databaseName: *database0Name
39 documents:
40 - _id: { $oid: "000000000000000000000005" }
41 files_id: { $oid: "000000000000000000000005" }
42 n: 0
43 data: { $binary: { base64: "ESIzRA==", subType: "00" } } # hex: 11223344
44 - _id: { $oid: "000000000000000000000006" }
45 files_id: { $oid: "000000000000000000000005" }
46 n: 1
47 data: { $binary: { base64: "VWZ3iA==", subType: "00" } } # hex: 55667788
48 - _id: { $oid: "000000000000000000000007" }
49 files_id: { $oid: "000000000000000000000005" }
50 n: 2
51 data: { $binary: { base64: "mao=", subType: "00" } } # hex: 99aa
52
53tests:
54 # Changed from original test ("length is 8") to operate on same initialData
55 - description: "Delete when length is 10"
56 operations:
57 - name: delete
58 object: *bucket0
59 arguments:
60 id: { $oid: "000000000000000000000005" }
61 # Original test uses "assert.data" syntax to modify outcome collection for
62 # comparison. This can be accomplished using "outcome" directly.
63 outcome:
64 - collectionName: *bucket0_files_collectionName
65 databaseName: *database0Name
66 documents: []
67 - collectionName: *bucket0_chunks_collectionName
68 databaseName: *database0Name
69 documents: []
70
71 - description: "Download when there are three chunks"
72 operations:
73 # Original test uses "download" operation. We use an explicit operation
74 # that returns a stream and then assert the contents of that stream.
75 - name: download
76 object: *bucket0
77 arguments:
78 id: { $oid: "000000000000000000000005" }
79 expectResult: { $$matchesHexBytes: "112233445566778899aa" }
80
81 - description: "Download when files entry does not exist"
82 operations:
83 - name: download
84 object: *bucket0
85 arguments:
86 id: { $oid: "000000000000000000000000" }
87 # Original test expects "FileNotFound" error, which isn't specified
88 expectError: { isError: true }
89
90 - description: "Download when an intermediate chunk is missing"
91 operations:
92 # Original test uses "arrange" syntax to modify initialData. This can be
93 # accomplished as a delete operation on the chunks collection.
94 - name: deleteOne
95 object: *bucket0_chunks_collection
96 arguments:
97 filter:
98 files_id: { $oid: "000000000000000000000005" }
99 n: 1
100 expectResult:
101 deletedCount: 1
102 - name: download
103 object: *bucket0
104 arguments:
105 id: { $oid: "000000000000000000000005" }
106 # Original test expects "ChunkIsMissing" error, which isn't specified
107 expectError: { isError: true }
108
109 - description: "Upload when length is 5"
110 operations:
111 # Original test uses "upload" operation. We use an explicit operation
112 # that takes a stream, which has been created from the expected hex bytes.
113 - name: upload
114 object: *bucket0
115 arguments:
116 filename: filename
117 source: { $$hexBytes: "1122334455" }
118 chunkSizeBytes: 4
119 # Original test references the result directly in "assert.data". Here,
120 # we need to save the result as an entity, which we can later reference.
121 expectResult: { $$type: objectId }
122 saveResultAsEntity: &oid0 oid0
123 # "outcome" does not allow operators, but we can perform the assertions
124 # with separate find operations.
125 - name: find
126 object: *bucket0_files_collection
127 arguments:
128 filter: {}
129 sort: { uploadDate: -1 }
130 limit: 1
131 expectResult:
132 - _id: { $$matchesEntity: *oid0 }
133 length: 5
134 chunkSize: 4
135 uploadDate: { $$type: date }
136 # The md5 field is deprecated so some drivers do not calculate it when uploading files.
137 md5: { $$unsetOrMatches: "283d4fea5dded59cf837d3047328f5af" }
138 filename: filename
139 - name: find
140 object: *bucket0_chunks_collection
141 arguments:
142 # We cannot use the saved ObjectId when querying, but filtering by a
143 # non-zero timestamp will exclude initialData and sort can return the
144 # expected chunks in order.
145 filter: { _id: { $gt: { $oid: "000000000000000000000007" } } }
146 sort: { n: 1 }
147 expectResult:
148 - _id: { $$type: objectId }
149 files_id: { $$matchesEntity: *oid0 }
150 n: 0
151 data: { $binary: { base64: "ESIzRA==", subType: "00" } } # hex 11223344
152 - _id: { $$type: objectId }
153 files_id: { $$matchesEntity: *oid0 }
154 n: 1
155 data: { $binary: { base64: "VQ==", subType: "00" } } # hex 55
View as plain text