...

Text file src/go.mongodb.org/mongo-driver/testdata/gridfs/download.yml

Documentation: go.mongodb.org/mongo-driver/testdata/gridfs

     1description: "gridfs-download"
     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": "000000000000000000000001" }
    29        length: 0
    30        chunkSize: 4
    31        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    32        md5: "d41d8cd98f00b204e9800998ecf8427e"
    33        filename: "length-0"
    34        contentType: "application/octet-stream"
    35        aliases: []
    36        metadata: {}
    37      - _id: { "$oid": "000000000000000000000002" }
    38        length: 0
    39        chunkSize: 4
    40        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    41        md5: "d41d8cd98f00b204e9800998ecf8427e"
    42        filename: "length-0-with-empty-chunk"
    43        contentType: "application/octet-stream"
    44        aliases: []
    45        metadata: {}
    46      - _id: { "$oid": "000000000000000000000003" }
    47        length: 2
    48        chunkSize: 4
    49        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    50        md5: "c700ed4fdb1d27055aa3faa2c2432283"
    51        filename: "length-2"
    52        contentType: "application/octet-stream"
    53        aliases: []
    54        metadata: {}
    55      - _id: { "$oid": "000000000000000000000004" }
    56        length: 8
    57        chunkSize: 4
    58        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    59        md5: "dd254cdc958e53abaa67da9f797125f5"
    60        filename: "length-8"
    61        contentType: "application/octet-stream"
    62        aliases: []
    63        metadata: {}
    64      - _id: { "$oid": "000000000000000000000005" }
    65        length: 10
    66        chunkSize: 4
    67        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    68        md5: "57d83cd477bfb1ccd975ab33d827a92b"
    69        filename: "length-10"
    70        contentType: "application/octet-stream"
    71        aliases: []
    72        metadata: {}
    73      - _id: { "$oid": "000000000000000000000006" }
    74        length: 2
    75        chunkSize: 4
    76        uploadDate: { "$date": "1970-01-01T00:00:00.000Z" }
    77        md5: "c700ed4fdb1d27055aa3faa2c2432283"
    78        # filename is intentionally omitted
    79        contentType: "application/octet-stream"
    80        aliases: []
    81        metadata: {}
    82  - collectionName: *bucket0_chunks_collectionName
    83    databaseName: *database0Name
    84    documents:
    85      - _id: { "$oid": "000000000000000000000001" }
    86        files_id: { "$oid": "000000000000000000000002" }
    87        n: 0
    88        data: { "$binary": { "base64": "", "subType": "00" } }
    89      - _id: { "$oid": "000000000000000000000002" }
    90        files_id: { "$oid": "000000000000000000000003" }
    91        n: 0
    92        data: { "$binary": { "base64": "ESI=", "subType": "00" } } # hex: 1122
    93      - _id: { "$oid": "000000000000000000000003" }
    94        files_id: { "$oid": "000000000000000000000004" }
    95        n: 0
    96        data: { "$binary": { "base64": "ESIzRA==", "subType": "00" } }  # hex: 11223344
    97      - _id: { "$oid": "000000000000000000000004" }
    98        files_id: { "$oid": "000000000000000000000004" }
    99        n: 1
   100        data: { "$binary": { "base64": "VWZ3iA==", "subType": "00" } } # hex: 55667788
   101      - _id: { "$oid": "000000000000000000000005" }
   102        files_id: { "$oid": "000000000000000000000005" }
   103        n: 0
   104        data: { "$binary": { "base64": "ESIzRA==", "subType": "00" } }  # hex: 11223344
   105      - _id: { "$oid": "000000000000000000000006" }
   106        files_id: { "$oid": "000000000000000000000005" }
   107        n: 1
   108        data: { "$binary": { "base64": "VWZ3iA==", "subType": "00" } } # hex: 55667788
   109      - _id: { "$oid": "000000000000000000000007" }
   110        files_id: { "$oid": "000000000000000000000005" }
   111        n: 2
   112        data: { "$binary" : { "base64": "mao=", "subType" : "00" } } # hex: 99aa
   113      - _id: { "$oid": "000000000000000000000008" }
   114        files_id: { "$oid": "000000000000000000000006" }
   115        n: 0
   116        data: { "$binary": { "base64": "ESI=", "subType": "00" } } # hex: 1122
   117
   118tests:
   119  - description: "download when length is zero"
   120    operations:
   121      - name: download
   122        object: *bucket0
   123        arguments:
   124          id: { $oid: "000000000000000000000001" }
   125        expectResult: { $$matchesHexBytes: "" }
   126  - description: "download when length is zero and there is one empty chunk"
   127    operations:
   128      - name: download
   129        object: *bucket0
   130        arguments:
   131          id: { $oid: "000000000000000000000002" }
   132        expectResult: { $$matchesHexBytes: "" }
   133  - description: "download when there is one chunk"
   134    operations:
   135      - name: download
   136        object: *bucket0
   137        arguments:
   138          id: { $oid: "000000000000000000000003" }
   139        expectResult: { $$matchesHexBytes: "1122" }
   140  - description: "download when there are two chunks"
   141    operations:
   142      - name: download
   143        object: *bucket0
   144        arguments:
   145          id: { $oid: "000000000000000000000004" }
   146        expectResult: { $$matchesHexBytes: "1122334455667788" }
   147  - description: "download when there are three chunks"
   148    operations:
   149      - name: download
   150        object: *bucket0
   151        arguments:
   152          id: { $oid: "000000000000000000000005" }
   153        expectResult: { $$matchesHexBytes: "112233445566778899aa" }
   154  - description: "download when files entry does not exist"
   155    operations:
   156      - name: download
   157        object: *bucket0
   158        arguments:
   159          id: { $oid: "000000000000000000000000" }
   160        expectError: { isError: true } # FileNotFound
   161  - description: "download when an intermediate chunk is missing"
   162    operations:
   163      - name: deleteOne
   164        object: *bucket0_chunks_collection
   165        arguments:
   166          filter:
   167            files_id: { $oid: "000000000000000000000005" }
   168            n: 1
   169        expectResult:
   170          deletedCount: 1
   171      - name: download
   172        object: *bucket0
   173        arguments:
   174          id: { $oid: "000000000000000000000005" }
   175        expectError: { isError: true } # ChunkIsMissing
   176  - description: "download when final chunk is missing"
   177    operations:
   178      - name: deleteOne
   179        object: *bucket0_chunks_collection
   180        arguments:
   181          filter:
   182            files_id: { $oid: "000000000000000000000005" }
   183            n: 2
   184        expectResult:
   185          deletedCount: 1
   186      - name: download
   187        object: *bucket0
   188        arguments:
   189          id: { $oid: "000000000000000000000005" }
   190        expectError: { isError: true } # ChunkIsMissing
   191  - description: "download when an intermediate chunk is the wrong size"
   192    operations:
   193      - name: bulkWrite
   194        object: *bucket0_chunks_collection
   195        arguments:
   196          requests:
   197            - updateOne:
   198                filter:
   199                  files_id: { $oid: "000000000000000000000005" }
   200                  n: 1
   201                update:
   202                  $set: { data: { "$binary": { "base64": "VWZ3", "subType": "00" } } } # hex: 556677
   203            - updateOne:
   204                filter:
   205                  files_id: { $oid: "000000000000000000000005" }
   206                  n: 2
   207                update:
   208                  $set: { data: { "$binary": { "base64": "iJmq", "subType": "00" } } } # hex: 8899aa
   209        expectResult:
   210          matchedCount: 2
   211          modifiedCount: 2
   212      - name: download
   213        object: *bucket0
   214        arguments:
   215          id: { $oid: "000000000000000000000005" }
   216        expectError: { isError: true } # ChunkIsWrongSize
   217  - description: "download when final chunk is the wrong size"
   218    operations:
   219      - name: updateOne
   220        object: *bucket0_chunks_collection
   221        arguments:
   222          filter:
   223            files_id: { $oid: "000000000000000000000005" }
   224            n: 2
   225          update:
   226            $set: { data: { "$binary": { "base64": "mQ==", "subType": "00" } } } # hex: 99
   227        expectResult:
   228          matchedCount: 1
   229          modifiedCount: 1
   230      - name: download
   231        object: *bucket0
   232        arguments:
   233          id: { $oid: "000000000000000000000005" }
   234        expectError: { isError: true } # ChunkIsWrongSize
   235  - description: "download legacy file with no name"
   236    operations:
   237      - name: download
   238        object: *bucket0
   239        arguments:
   240          id: { $oid: "000000000000000000000006" }
   241        expectResult: { $$matchesHexBytes: "1122" }

View as plain text