1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
(function() {
if (typeof getToolTest === "undefined") {
load('jstests/configs/plain_28.config.js');
}
// Testing exporting with various type specifiers
jsTest.log('Testing exporting with various type specifiers');
var toolTest = getToolTest('export_types');
var commonToolArgs = getCommonToolArguments();
// the db and collections we'll use
var testDB = toolTest.db.getSiblingDB('test');
var sourceColl = testDB.source;
// the export target
var exportTarget = 'type_export';
// insert some data
sourceColl.insert({a: 1});
sourceColl.insert({a: 1, b: 1});
sourceColl.insert({a: 1, b: 2, c: 3});
// sanity check the insertion worked
assert.eq(3, sourceColl.count());
// first validate that invalid types are rejected
var ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget,
'--db', 'test',
'--collection', 'source',
'--type="foobar"',
'--fields', 'a']
.concat(commonToolArgs));
assert.eq(3, ret);
// create a dump file using a lowercase csv type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".csv",
'--db', 'test',
'--collection', 'source',
'--type="csv"',
'--fields', 'a']
.concat(commonToolArgs));
assert.eq(0, ret);
var csvmd5 = md5sumFile(exportTarget + ".csv");
// create a dump file using a uppercase csv type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".CSV",
'--db', 'test',
'--collection', 'source',
'--type="CSV"',
'--fields', 'a']
.concat(commonToolArgs));
var CSVmd5 = md5sumFile(exportTarget + ".CSV");
// the files for the uppercase and lowercase types should match
assert.eq(csvmd5, CSVmd5);
// create a dump file using a mixedcase csv type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".cSv",
'--db', 'test',
'--collection', 'source',
'--type="cSv"',
'--fields', 'a']
.concat(commonToolArgs));
var cSvmd5 = md5sumFile(exportTarget + ".cSv");
// the files for the uppercase and lowercase types should match
assert.eq(csvmd5, cSvmd5);
// then some json type tests
// create a dump file using a lowercase json type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".json",
'--db', 'test',
'--collection', 'source',
'--type="json"',
'--fields', 'a']
.concat(commonToolArgs));
assert.eq(0, ret);
var jsonmd5 = md5sumFile(exportTarget + ".json");
// create a dump file using a uppercase json type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".JSON",
'--db', 'test',
'--collection', 'source',
'--type="JSON"',
'--fields', 'a']
.concat(commonToolArgs));
assert.eq(0, ret);
var JSONmd5 = md5sumFile(exportTarget + ".JSON");
// create a dump file using a uppercase blank (json) type
ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget + ".blank",
'--db', 'test',
'--collection', 'source',
'--fields', 'a']
.concat(commonToolArgs));
assert.eq(0, ret);
var blankmd5 = md5sumFile(exportTarget + ".blank");
assert.eq(JSONmd5, jsonmd5);
assert.eq(blankmd5, jsonmd5);
// sanity check
assert.neq(csvmd5, jsonmd5);
// success
toolTest.stop();
}());
|