0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/tool/tool1.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

2009-05-20 17:29:40 +02:00
// mongo tool tests, very basic to start with
baseName = "jstests_tool_tool1";
dbPath = MongoRunner.dataPath + baseName + "/";
externalPath = MongoRunner.dataPath + baseName + "_external/";
externalBaseName = "export.json";
externalFile = externalPath + externalBaseName;
2009-05-20 17:29:40 +02:00
function fileSize(){
var l = listFiles( externalPath );
for ( var i=0; i<l.length; i++ ){
if ( l[i].baseName == externalBaseName )
return l[i].size;
}
return -1;
}
2009-05-20 17:29:40 +02:00
port = allocatePorts( 1 )[ 0 ];
resetDbpath( externalPath );
2009-05-20 17:29:40 +02:00
2010-10-29 19:38:13 +02:00
m = startMongod( "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--noprealloc" , "--bind_ip", "127.0.0.1" );
2009-05-20 17:29:40 +02:00
c = m.getDB( baseName ).getCollection( baseName );
c.save( { a: 1 } );
assert( c.findOne() );
2009-05-20 17:29:40 +02:00
runMongoProgram( "mongodump", "--host", "127.0.0.1:" + port, "--out", externalPath );
2009-05-20 17:29:40 +02:00
c.drop();
runMongoProgram( "mongorestore", "--host", "127.0.0.1:" + port, "--dir", externalPath );
assert.soon( "c.findOne()" , "mongodump then restore has no data w/sleep" );
assert( c.findOne() , "mongodump then restore has no data" );
assert.eq( 1 , c.findOne().a , "mongodump then restore has no broken data" );
2009-05-20 17:29:40 +02:00
resetDbpath( externalPath );
assert.eq( -1 , fileSize() , "mongoexport prep invalid" );
runMongoProgram( "mongoexport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--out", externalFile );
assert.lt( 10 , fileSize() , "file size changed" );
2009-05-20 17:29:40 +02:00
c.drop();
runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--file", externalFile );
2009-08-28 19:35:08 +02:00
assert.soon( "c.findOne()" , "mongo import json A" );
assert( c.findOne() && 1 == c.findOne().a , "mongo import json B" );