Commit 3cf99441 authored by Jeremy Mikola's avatar Jeremy Mikola

Rewrite harness for GridFS spec tests

parent 583d65ab
This diff is collapsed.
GridFS Tests
============
The YAML and JSON files in this directory are platform-independent tests
meant to exercise a driver's implementation of GridFS.
Converting to JSON
==================
The tests are written in YAML because it is easier for humans to write
and read, and because YAML supports a standard comment format. Each test
is also provided in JSON format because in some languages it is easier
to parse JSON than YAML.
If you modify any test, you should modify the YAML file and then
regenerate the JSON file from it.
One way to convert the files is using an online web page. I used:
http://www.json2yaml.com/
It's advertised as a JSON to YAML converter but it can be used in either direction.
Note: the yaml2json utility from npm is not capable of converting these YAML tests
because it doesn't implement the full YAML spec.
Format
======
Each test file has two top level sections:
1. data
2. tests
The data section defines the initial contents of the files and chunks
collections for all tests in that file.
The tests section defines the tests to be run. The format of the tests
section will vary slightly depending on what tests are being defined.
In general, they will have the following sections:
1. description
2. arrange
3. act
4. assert
The arrange section, if present, defines changes to be made to the
initial contents of the files and chunks collections (as defined by
the data section) before this particular test is run. These changes
are described in the form of write commands that can be sent directly
to MongoDB.
The act section defines what operation (with which arguments) should
be performed.
The assert section defines what should be true at the end of the test.
This includes checking the return value of the operation, as well as
checking the expected contents of the files and chunks collections. The
expected contents of the files and chunks collections are described
in the form of write commands that modify collections named
expected.files and expected.chunks. Before running these commands,
load the initial files and chunks documents into the expected.files
and expected.chunks collections and then run the commands. At that point
you can assert that fs.files and expected.files are the same, and that
expected.chunks and fs.chunks are the same.
For operations that are expected to succeed the assert section contains
a "result" element describing the expected result. For operations
that are expected to fail the assert section contains an "error"
element describing the expected failure.
The "result" element is either the expected result when it is possible to
know the result in advance, or it is the special value "&result"
which means that we expect a result (not a failure) but the actual
value of the result could be anything. The notation "&result" is
modeled after YAML syntax for defining an anchor, and the
result value may be referenced later in the assert section as
"*result".
Another special notation in the assert section is "*actual", which
is used when the value of a field cannot be known in advance of the
test, so the assert logic should accept whatever the actual value
ended up being.
data:
files:
-
_id: { "$oid" : "000000000000000000000001" }
length: 0
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "d41d8cd98f00b204e9800998ecf8427e"
filename: "length-0"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000002" }
length: 0
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "d41d8cd98f00b204e9800998ecf8427e"
filename: "length-0-with-empty-chunk"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000003" }
length: 2
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "c700ed4fdb1d27055aa3faa2c2432283"
filename: "length-2"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000004" }
length: 8
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "dd254cdc958e53abaa67da9f797125f5"
filename: "length-8"
contentType: "application/octet-stream"
aliases: []
metadata: {}
chunks:
- { _id : { "$oid" : "000000000000000000000001" }, files_id : { "$oid" : "000000000000000000000002" }, n : 0, data : { $hex : "" } }
- { _id : { "$oid" : "000000000000000000000002" }, files_id : { "$oid" : "000000000000000000000003" }, n : 0, data : { $hex : "1122" } }
- { _id : { "$oid" : "000000000000000000000003" }, files_id : { "$oid" : "000000000000000000000004" }, n : 0, data : { $hex : "11223344" } }
- { _id : { "$oid" : "000000000000000000000004" }, files_id : { "$oid" : "000000000000000000000004" }, n : 1, data : { $hex : "55667788" } }
tests:
-
description: "Delete when length is 0"
act:
operation: delete
arguments:
id: { "$oid" : "000000000000000000000001" }
assert:
result: void
data:
-
{ delete : "expected.files", deletes : [
{ q : { _id : { "$oid" : "000000000000000000000001" } }, limit : 1 }
] }
-
description: "Delete when length is 0 and there is one extra empty chunk"
act:
operation: delete
arguments:
id: { "$oid" : "000000000000000000000002" }
assert:
result: void
data:
-
{ delete : "expected.files", deletes : [
{ q : { _id : { "$oid" : "000000000000000000000002" } }, limit : 1 }
] }
-
{ delete : "expected.chunks", deletes : [
{ q : { files_id : { "$oid" : "000000000000000000000002" } }, limit : 0 }
] }
-
description: "Delete when length is 8"
act:
operation: delete
arguments:
id: { "$oid" : "000000000000000000000004" }
assert:
result: void
data:
-
{ delete : "expected.files", deletes : [
{ q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
] }
-
{ delete : "expected.chunks", deletes : [
{ q : { files_id : { "$oid" : "000000000000000000000004" } }, limit : 0 }
] }
-
description: "Delete when files entry does not exist"
act:
operation: delete
arguments:
id: { "$oid" : "000000000000000000000000" }
assert:
error: "FileNotFound"
-
description: "Delete when files entry does not exist and there are orphaned chunks"
arrange:
data:
-
{ delete : "fs.files", deletes : [
{ q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
] }
act:
operation: delete
arguments:
id: { "$oid" : "000000000000000000000004" }
assert:
error: "FileNotFound"
data:
-
{ delete : "expected.files", deletes : [
{ q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
] }
-
{ delete : "expected.chunks", deletes : [
{ q : { files_id : { "$oid" : "000000000000000000000004" } }, limit : 0 }
] }
data:
files:
-
_id: { "$oid" : "000000000000000000000001" }
length: 0
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "d41d8cd98f00b204e9800998ecf8427e"
filename: "length-0"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000002" }
length: 0
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "d41d8cd98f00b204e9800998ecf8427e"
filename: "length-0-with-empty-chunk"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000003" }
length: 2
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "c700ed4fdb1d27055aa3faa2c2432283"
filename: "length-2"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000004" }
length: 8
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "dd254cdc958e53abaa67da9f797125f5"
filename: "length-8"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000005" }
length: 10
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "57d83cd477bfb1ccd975ab33d827a92b"
filename: "length-10"
contentType: "application/octet-stream"
aliases: []
metadata: {}
chunks:
- { _id : { "$oid" : "000000000000000000000001" }, files_id : { "$oid" : "000000000000000000000002" }, n : 0, data : { $hex : "" } }
- { _id : { "$oid" : "000000000000000000000002" }, files_id : { "$oid" : "000000000000000000000003" }, n : 0, data : { $hex : "1122" } }
- { _id : { "$oid" : "000000000000000000000003" }, files_id : { "$oid" : "000000000000000000000004" }, n : 0, data : { $hex : "11223344" } }
- { _id : { "$oid" : "000000000000000000000004" }, files_id : { "$oid" : "000000000000000000000004" }, n : 1, data : { $hex : "55667788" } }
- { _id : { "$oid" : "000000000000000000000005" }, files_id : { "$oid" : "000000000000000000000005" }, n : 0, data : { $hex : "11223344" } }
- { _id : { "$oid" : "000000000000000000000006" }, files_id : { "$oid" : "000000000000000000000005" }, n : 1, data : { $hex : "55667788" } }
- { _id : { "$oid" : "000000000000000000000007" }, files_id : { "$oid" : "000000000000000000000005" }, n : 2, data : { $hex : "99aa" } }
tests:
-
description: "Download when length is zero"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000001" }
options: { }
assert:
result: { $hex : "" }
-
description: "Download when length is zero and there is one empty chunk"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000002" }
options: { }
assert:
result: { $hex : "" }
-
description: "Download when there is one chunk"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000003" }
options: { }
assert:
result: { $hex : "1122" }
-
description: "Download when there are two chunks"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000004" }
options: { }
assert:
result: { $hex : "1122334455667788" }
-
description: "Download when there are three chunks"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000005" }
options: { }
assert:
result: { $hex : "112233445566778899aa" }
-
description: "Download when files entry does not exist"
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000000" }
options: { }
assert:
error: "FileNotFound"
-
description: "Download when an intermediate chunk is missing"
arrange:
data:
-
{ delete : "fs.chunks", deletes : [
{ q : { files_id : { "$oid" : "000000000000000000000005" }, n : 1 }, limit : 1 }
] }
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000005" }
assert:
error: "ChunkIsMissing"
-
description: "Download when final chunk is missing"
arrange:
data:
-
{ delete : "fs.chunks", deletes : [
{ q : { files_id : { "$oid" : "000000000000000000000005" }, n : 1 }, limit : 1 }
] }
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000005" }
assert:
error: "ChunkIsMissing"
-
description: "Download when an intermediate chunk is the wrong size"
arrange:
data:
-
{ update : "fs.chunks", updates : [
{ q : { files_id : { "$oid" : "000000000000000000000005" }, n : 1 }, u : { $set : { data : { $hex : "556677" } } } },
{ q : { files_id : { "$oid" : "000000000000000000000005" }, n : 2 }, u : { $set : { data : { $hex : "8899aa" } } } }
] }
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000005" }
assert:
error: "ChunkIsWrongSize"
-
description: "Download when final chunk is the wrong size"
arrange:
data:
-
{ update : "fs.chunks", updates : [
{ q : { files_id : { "$oid" : "000000000000000000000005" }, n : 2 }, u : { $set : { data : { $hex : "99" } } } }
] }
act:
operation: download
arguments:
id: { "$oid" : "000000000000000000000005" }
assert:
error: "ChunkIsWrongSize"
data:
files:
-
_id: { "$oid" : "000000000000000000000001" }
length: 1
chunkSize: 4
uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
md5: "47ed733b8d10be225eceba344d533586"
filename: "abc"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000002" }
length: 1
chunkSize: 4
uploadDate: { "$date" : "1970-01-02T00:00:00.000Z" }
md5: "b15835f133ff2e27c7cb28117bfae8f4"
filename: "abc"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000003" }
length: 1
chunkSize: 4
uploadDate: { "$date" : "1970-01-03T00:00:00.000Z" }
md5: "eccbc87e4b5ce2fe28308fd9f2a7baf3"
filename: "abc"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000004" }
length: 1
chunkSize: 4
uploadDate: { "$date" : "1970-01-04T00:00:00.000Z" }
md5: "f623e75af30e62bbd73d6df5b50bb7b5"
filename: "abc"
contentType: "application/octet-stream"
aliases: []
metadata: {}
-
_id: { "$oid" : "000000000000000000000005" }
length: 1
chunkSize: 4
uploadDate: { "$date" : "1970-01-05T00:00:00.000Z" }
md5: "4c614360da93c0a041b22e537de151eb"
filename: "abc"
contentType: "application/octet-stream"
aliases: []
metadata: {}
chunks:
- { _id : { "$oid" : "000000000000000000000001" }, files_id : { "$oid" : "000000000000000000000001" }, n : 0, data : { $hex : "11" } }
- { _id : { "$oid" : "000000000000000000000002" }, files_id : { "$oid" : "000000000000000000000002" }, n : 0, data : { $hex : "22" } }
- { _id : { "$oid" : "000000000000000000000003" }, files_id : { "$oid" : "000000000000000000000003" }, n : 0, data : { $hex : "33" } }
- { _id : { "$oid" : "000000000000000000000004" }, files_id : { "$oid" : "000000000000000000000004" }, n : 0, data : { $hex : "44" } }
- { _id : { "$oid" : "000000000000000000000005" }, files_id : { "$oid" : "000000000000000000000005" }, n : 0, data : { $hex : "55" } }
tests:
-
description: "Download_by_name when revision is 0"
act:
operation: download_by_name
arguments:
filename: "abc"
options: { revision : 0 }
assert:
result: { $hex : "11" }
-
description: "Download_by_name when revision is 1"
act:
operation: download_by_name
arguments:
filename: "abc"
options: { revision : 1 }
assert:
result: { $hex : "22" }
-
description: "Download_by_name when revision is -2"
act:
operation: download_by_name
arguments:
filename: "abc"
options: { revision : -2 }
assert:
result: { $hex : "44" }
-
description: "Download_by_name when revision is -1"
act:
operation: download_by_name
arguments:
filename: "abc"
options: { revision : -1 }
assert:
result: { $hex : "55" }
-
description: "Download_by_name when files entry does not exist"
act:
operation: download_by_name
arguments:
filename: "xyz"
assert:
error: "FileNotFound"
-
description: "Download_by_name when revision does not exist"
act:
operation: download_by_name
arguments:
filename: "abc"
options: { revision : 999 }
assert:
error: "RevisionNotFound"
data:
files: []
chunks: []
tests:
-
description: "Upload when length is 0"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 0, chunkSize : 4, uploadDate : "*actual", md5 : "d41d8cd98f00b204e9800998ecf8427e", filename : "filename" }
] }
-
description: "Upload when length is 1"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "11" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 1, chunkSize : 4, uploadDate : "*actual", md5 : "47ed733b8d10be225eceba344d533586", filename : "filename" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11" } }
] }
-
description: "Upload when length is 3"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "112233" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 3, chunkSize : 4, uploadDate : "*actual", md5 : "bafae3a174ab91fc70db7a6aa50f4f52", filename : "filename" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "112233" } }
] }
-
description: "Upload when length is 4"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "11223344" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 4, chunkSize : 4, uploadDate : "*actual", md5 : "7e7c77cff5705d1f7574a25ef6662117", filename : "filename" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11223344" } }
] }
-
description: "Upload when length is 5"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "1122334455" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 5, chunkSize : 4, uploadDate : "*actual", md5 : "283d4fea5dded59cf837d3047328f5af", filename : "filename" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11223344" } },
{ _id : "*actual", files_id : "*result", n : 1, data : { $hex : "55" } }
] }
-
description: "Upload when length is 8"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "1122334455667788" }
options: { chunkSizeBytes : 4 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 8, chunkSize : 4, uploadDate : "*actual", md5 : "dd254cdc958e53abaa67da9f797125f5", filename : "filename" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11223344" } },
{ _id : "*actual", files_id : "*result", n : 1, data : { $hex : "55667788" } }
] }
-
description: "Upload when contentType is provided"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "11" }
options: { chunkSizeBytes : 4, contentType : "image/jpeg" }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 1, chunkSize : 4, uploadDate : "*actual", md5 : "47ed733b8d10be225eceba344d533586", filename : "filename", contentType : "image/jpeg" }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11" } }
] }
-
description: "Upload when metadata is provided"
act:
operation: upload
arguments:
filename: "filename"
source: { $hex : "11" }
options:
chunkSizeBytes: 4
metadata: { x : 1 }
assert:
result: "&result"
data:
-
{ insert : "expected.files", documents : [
{ _id : "*result", length : 1, chunkSize : 4, uploadDate : "*actual", md5 : "47ed733b8d10be225eceba344d533586", filename : "filename", metadata : { x : 1 } }
] }
-
{ insert : "expected.chunks", documents : [
{ _id : "*actual", files_id : "*result", n : 0, data : { $hex : "11" } }
] }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment