Best JavaScript code snippet using mountebank
replication.js
Source:replication.js
...264////////////////////////////////////////////////////////////////////////////////265 testLoggerCreateCollection : function () {266 var tick = getLastLogTick();267 var c = db._create(cn);268 var entry = getLogEntries(tick, 2000)[0];269 assertEqual(2000, entry.type);270 assertEqual(2, entry.data.type);271 assertEqual(c._id, entry.cid);272 assertEqual(c._id, entry.data.cid);273 assertFalse(entry.data.deleted);274 assertEqual(cn, entry.data.name);275 },276////////////////////////////////////////////////////////////////////////////////277/// @brief test actions278////////////////////////////////////////////////////////////////////////////////279 testLoggerDropCollection : function () {280 var c = db._create(cn);281 var tick = getLastLogTick();282 db._drop(cn);283 var entry = getLogEntries(tick, 2001)[0];284 assertEqual(2001, entry.type);285 assertEqual(c._id, entry.cid);286 },287////////////////////////////////////////////////////////////////////////////////288/// @brief test actions289////////////////////////////////////////////////////////////////////////////////290 testLoggerRenameCollection : function () {291 var c = db._create(cn);292 var tick = getLastLogTick();293 c.rename(cn2);294 var entry = getLogEntries(tick, 2002)[0];295 assertEqual(2002, entry.type);296 assertEqual(c._id, entry.cid);297 assertEqual(cn2, entry.data.name);298 },299////////////////////////////////////////////////////////////////////////////////300/// @brief test actions301////////////////////////////////////////////////////////////////////////////////302 testLoggerPropertiesCollection : function () {303 var c = db._create(cn);304 var tick = getLastLogTick();305 c.properties({ waitForSync: true, journalSize: 2097152 });306 var entry = getLogEntries(tick, 2003)[0];307 assertEqual(2003, entry.type);308 assertEqual(c._id, entry.cid, JSON.stringify(entry));309 assertEqual(c._id, entry.data.cid);310 assertEqual(cn, entry.data.name);311 assertEqual(2, entry.data.type);312 assertEqual(false, entry.data.deleted);313 assertEqual(2097152, entry.data.journalSize);314 assertEqual(true, entry.data.waitForSync);315 },316////////////////////////////////////////////////////////////////////////////////317/// @brief test actions318////////////////////////////////////////////////////////////////////////////////319 testLoggerIncludedSystemCollection1 : function () {320 var c = db._collection("_graphs");321 var tick = getLastLogTick();322 var doc = c.save({ "test": 1 });323 var entry = getLogEntries(tick, 2300)[0];324 assertEqual(2300, entry.type);325 assertEqual(c._id, entry.cid, JSON.stringify(entry));326 tick = getLastLogTick();327 c.remove(doc._key);328 entry = getLogEntries(tick, 2302)[0];329 assertEqual(2302, entry.type);330 assertEqual(c._id, entry.cid, JSON.stringify(entry));331 assertEqual(doc._key, entry.data._key);332 },333////////////////////////////////////////////////////////////////////////////////334/// @brief test actions335////////////////////////////////////////////////////////////////////////////////336 testLoggerIncludedSystemCollection2 : function () {337 var c = db._collection("_users");338 var tick = getLastLogTick();339 var doc = c.save({ "test": 1 });340 var entry = getLogEntries(tick, 2300)[0];341 assertEqual(2300, entry.type);342 assertEqual(c._id, entry.cid, JSON.stringify(entry));343 tick = getLastLogTick();344 c.remove(doc._key);345 entry = getLogEntries(tick, 2302)[0];346 assertEqual(2302, entry.type);347 assertEqual(c._id, entry.cid, JSON.stringify(entry));348 assertEqual(doc._key, entry.data._key);349 },350////////////////////////////////////////////////////////////////////////////////351/// @brief test actions352////////////////////////////////////////////////////////////////////////////////353 testLoggerSystemCollection : function () {354 db._drop("_unitfoxx");355 db._drop("_unittests");356 var tick = getLastLogTick();357 var c = db._create("_unittests", { isSystem : true });358 var entry = getLogEntries(tick, 2000)[0];359 assertEqual(2000, entry.type);360 assertEqual(c._id, entry.cid, JSON.stringify(entry));361 assertEqual(c.name(), entry.data.name);362 tick = getLastLogTick();363 c.properties({ waitForSync : true });364 entry = getLogEntries(tick, 2003)[0];365 assertEqual(2003, entry.type);366 assertEqual(c._id, entry.cid, JSON.stringify(entry));367 assertEqual(true, entry.data.waitForSync);368 tick = getLastLogTick();369 },370////////////////////////////////////////////////////////////////////////////////371/// @brief test actions372////////////////////////////////////////////////////////////////////////////////373 testLoggerTruncateCollection1 : function () {374 var c = db._create(cn);375 c.save({ "test": 1, "_key": "abc" });376 var tick = getLastLogTick();377 c.truncate();378 var entry = getLogEntries(tick, 2302);379 assertEqual(1, entry.length);380 assertNotEqual("0", entry[0].tid);381 assertEqual(c._id, entry[0].cid);382 assertEqual("abc", entry[0].data._key);383 c.save({ "test": 1, "_key": "abc" });384 tick = getLastLogTick();385 c.truncate();386 entry = getLogEntries(tick, 2302);387 assertNotEqual("0", entry[0].tid);388 assertEqual(c._id, entry[0].cid);389 assertEqual("abc", entry[0].data._key);390 },391////////////////////////////////////////////////////////////////////////////////392/// @brief test actions393////////////////////////////////////////////////////////////////////////////////394 testLoggerTruncateCollection2 : function () {395 var i;396 var c = db._create(cn);397 for (i = 0; i < 100; ++i) {398 c.save({ "test": 1, "_key": "test" + i });399 }400 var tick = getLastLogTick();401 c.truncate();402 getLastLogTick();403 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2302 ]);404 assertEqual(102, entry.length);405 // trx start406 assertEqual(2200, entry[0].type);407 assertNotEqual("", entry[0].tid);408 var tid = entry[0].tid;409 // remove410 var keys = { };411 for (i = 0; i < 100; ++i) {412 assertEqual(2302, entry[i + 1].type);413 assertEqual(tid, entry[i + 1].tid);414 assertEqual(c._id, entry[i + 1].cid);415 keys[entry[i + 1].data._key] = true;416 }417 assertEqual(100, Object.keys(keys).length);418 // commit419 assertEqual(2201, entry[101].type);420 assertEqual(tid, entry[101].tid);421 },422////////////////////////////////////////////////////////////////////////////////423/// @brief test actions424////////////////////////////////////////////////////////////////////////////////425 testLoggerCreateIndexHash1 : function () {426 var c = db._create(cn);427 var tick = getLastLogTick();428 c.ensureUniqueConstraint("a", "b");429 var idx = c.getIndexes()[1];430 var entry = getLogEntries(tick, 2100)[0];431 assertTrue(2100, entry.type);432 assertEqual(c._id, entry.cid, JSON.stringify(entry));433 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);434 assertEqual("hash", entry.data.type);435 assertEqual(true, entry.data.unique);436 assertEqual(false, entry.data.sparse);437 assertEqual([ "a", "b" ], entry.data.fields);438 },439////////////////////////////////////////////////////////////////////////////////440/// @brief test actions441////////////////////////////////////////////////////////////////////////////////442 testLoggerCreateIndexHash2 : function () {443 var c = db._create(cn);444 var tick = getLastLogTick();445 c.ensureHashIndex("a");446 var idx = c.getIndexes()[1];447 var entry = getLogEntries(tick, 2100)[0];448 assertEqual(c._id, entry.cid, JSON.stringify(entry));449 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);450 assertEqual("hash", entry.data.type);451 assertEqual(false, entry.data.unique);452 assertEqual(false, entry.data.sparse);453 assertEqual([ "a" ], entry.data.fields);454 },455////////////////////////////////////////////////////////////////////////////////456/// @brief test actions457////////////////////////////////////////////////////////////////////////////////458 testLoggerCreateIndexSparseHash1 : function () {459 var c = db._create(cn);460 var tick = getLastLogTick();461 c.ensureUniqueConstraint("a", "b", { sparse: true });462 var idx = c.getIndexes()[1];463 var entry = getLogEntries(tick, 2100)[0];464 assertTrue(2100, entry.type);465 assertEqual(c._id, entry.cid, JSON.stringify(entry));466 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);467 assertEqual("hash", entry.data.type);468 assertEqual(true, entry.data.unique);469 assertEqual(true, entry.data.sparse);470 assertEqual([ "a", "b" ], entry.data.fields);471 },472////////////////////////////////////////////////////////////////////////////////473/// @brief test actions474////////////////////////////////////////////////////////////////////////////////475 testLoggerCreateIndexSparseHash2 : function () {476 var c = db._create(cn);477 var tick = getLastLogTick();478 c.ensureHashIndex("a", { sparse: true });479 var idx = c.getIndexes()[1];480 var entry = getLogEntries(tick, 2100)[0];481 assertEqual(c._id, entry.cid, JSON.stringify(entry));482 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);483 assertEqual("hash", entry.data.type);484 assertEqual(false, entry.data.unique);485 assertEqual(true, entry.data.sparse);486 assertEqual([ "a" ], entry.data.fields);487 },488////////////////////////////////////////////////////////////////////////////////489/// @brief test actions490////////////////////////////////////////////////////////////////////////////////491 testLoggerCreateIndexSkiplist1 : function () {492 var c = db._create(cn);493 var tick = getLastLogTick();494 c.ensureSkiplist("a", "b", "c");495 var idx = c.getIndexes()[1];496 var entry = getLogEntries(tick, 2100)[0];497 assertTrue(2100, entry.type);498 assertEqual(c._id, entry.cid, JSON.stringify(entry));499 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);500 assertEqual("skiplist", entry.data.type);501 assertEqual(false, entry.data.unique);502 assertEqual(false, entry.data.sparse);503 assertEqual([ "a", "b", "c" ], entry.data.fields);504 },505////////////////////////////////////////////////////////////////////////////////506/// @brief test actions507////////////////////////////////////////////////////////////////////////////////508 testLoggerCreateIndexSkiplist2 : function () {509 var c = db._create(cn);510 var tick = getLastLogTick();511 c.ensureUniqueSkiplist("a");512 var idx = c.getIndexes()[1];513 var entry = getLogEntries(tick, 2100)[0];514 assertEqual(c._id, entry.cid, JSON.stringify(entry));515 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);516 assertEqual("skiplist", entry.data.type);517 assertEqual(true, entry.data.unique);518 assertEqual(false, entry.data.sparse);519 assertEqual([ "a" ], entry.data.fields);520 },521////////////////////////////////////////////////////////////////////////////////522/// @brief test actions523////////////////////////////////////////////////////////////////////////////////524 testLoggerCreateIndexSparseSkiplist1 : function () {525 var c = db._create(cn);526 var tick = getLastLogTick();527 c.ensureSkiplist("a", "b", "c", { sparse: true });528 var idx = c.getIndexes()[1];529 var entry = getLogEntries(tick, 2100)[0];530 assertTrue(2100, entry.type);531 assertEqual(c._id, entry.cid, JSON.stringify(entry));532 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);533 assertEqual("skiplist", entry.data.type);534 assertEqual(false, entry.data.unique);535 assertEqual(true, entry.data.sparse);536 assertEqual([ "a", "b", "c" ], entry.data.fields);537 },538////////////////////////////////////////////////////////////////////////////////539/// @brief test actions540////////////////////////////////////////////////////////////////////////////////541 testLoggerCreateIndexSparseSkiplist2 : function () {542 var c = db._create(cn);543 var tick = getLastLogTick();544 c.ensureUniqueSkiplist("a", { sparse: true });545 var idx = c.getIndexes()[1];546 var entry = getLogEntries(tick, 2100)[0];547 assertEqual(c._id, entry.cid, JSON.stringify(entry));548 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);549 assertEqual("skiplist", entry.data.type);550 assertEqual(true, entry.data.unique);551 assertEqual(true, entry.data.sparse);552 assertEqual([ "a" ], entry.data.fields);553 },554////////////////////////////////////////////////////////////////////////////////555/// @brief test actions556////////////////////////////////////////////////////////////////////////////////557 testLoggerCreateIndexFulltext1 : function () {558 var c = db._create(cn);559 var tick = getLastLogTick();560 c.ensureFulltextIndex("a", 5);561 var idx = c.getIndexes()[1];562 var entry = getLogEntries(tick, 2100)[0];563 assertTrue(2100, entry.type);564 assertEqual(c._id, entry.cid, JSON.stringify(entry));565 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);566 assertEqual("fulltext", entry.data.type);567 assertEqual(false, entry.data.unique);568 assertEqual(5, entry.data.minLength);569 assertEqual([ "a" ], entry.data.fields);570 },571////////////////////////////////////////////////////////////////////////////////572/// @brief test actions573////////////////////////////////////////////////////////////////////////////////574 testLoggerCreateIndexGeo1 : function () {575 var c = db._create(cn);576 var tick = getLastLogTick();577 c.ensureGeoIndex("a", "b");578 var idx = c.getIndexes()[1];579 var entry = getLogEntries(tick, 2100)[0];580 assertTrue(2100, entry.type);581 assertEqual(c._id, entry.cid, JSON.stringify(entry));582 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);583 assertEqual("geo2", entry.data.type);584 assertEqual(false, entry.data.unique);585 assertEqual(false, entry.data.constraint);586 assertEqual([ "a", "b" ], entry.data.fields);587 },588////////////////////////////////////////////////////////////////////////////////589/// @brief test actions590////////////////////////////////////////////////////////////////////////////////591 testLoggerCreateIndexGeo2 : function () {592 var c = db._create(cn);593 var tick = getLastLogTick();594 c.ensureGeoIndex("a", true);595 var idx = c.getIndexes()[1];596 var entry = getLogEntries(tick, 2100)[0];597 assertTrue(2100, entry.type);598 assertEqual(c._id, entry.cid, JSON.stringify(entry));599 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);600 assertEqual("geo1", entry.data.type);601 assertEqual(false, entry.data.unique);602 assertEqual(false, entry.data.constraint);603 assertEqual([ "a" ], entry.data.fields);604 },605////////////////////////////////////////////////////////////////////////////////606/// @brief test actions607////////////////////////////////////////////////////////////////////////////////608 testLoggerCreateIndexGeo3 : function () {609 var c = db._create(cn);610 var tick = getLastLogTick();611 c.ensureGeoConstraint("a", "b", true);612 var idx = c.getIndexes()[1];613 var entry = getLogEntries(tick, 2100)[0];614 assertTrue(2100, entry.type);615 assertEqual(c._id, entry.cid, JSON.stringify(entry));616 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);617 assertEqual("geo2", entry.data.type);618 assertEqual(false, entry.data.unique);619 assertEqual(false, entry.data.constraint);620 assertEqual(true, entry.data.ignoreNull);621 assertEqual(true, entry.data.sparse);622 assertEqual([ "a", "b" ], entry.data.fields);623 },624////////////////////////////////////////////////////////////////////////////////625/// @brief test actions626////////////////////////////////////////////////////////////////////////////////627 testLoggerCreateIndexGeo4 : function () {628 var c = db._create(cn);629 var tick = getLastLogTick();630 c.ensureGeoConstraint("a", "b", false);631 var idx = c.getIndexes()[1];632 var entry = getLogEntries(tick, 2100)[0];633 assertTrue(2100, entry.type);634 assertEqual(c._id, entry.cid, JSON.stringify(entry));635 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);636 assertEqual("geo2", entry.data.type);637 assertEqual(false, entry.data.unique);638 assertEqual(false, entry.data.constraint);639 assertEqual(true, entry.data.ignoreNull);640 assertEqual(true, entry.data.sparse);641 assertEqual([ "a", "b" ], entry.data.fields);642 },643////////////////////////////////////////////////////////////////////////////////644/// @brief test actions645////////////////////////////////////////////////////////////////////////////////646 testLoggerCreateIndexGeo5 : function () {647 var c = db._create(cn);648 var tick = getLastLogTick();649 c.ensureGeoConstraint("a", true);650 var idx = c.getIndexes()[1];651 var entry = getLogEntries(tick, 2100)[0];652 assertTrue(2100, entry.type);653 assertEqual(c._id, entry.cid, JSON.stringify(entry));654 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);655 assertEqual("geo1", entry.data.type);656 assertEqual(false, entry.data.unique);657 assertEqual(false, entry.data.constraint);658 assertEqual(true, entry.data.ignoreNull);659 assertEqual(true, entry.data.sparse);660 assertEqual([ "a" ], entry.data.fields);661 },662////////////////////////////////////////////////////////////////////////////////663/// @brief test actions664////////////////////////////////////////////////////////////////////////////////665 testLoggerDropIndex : function () {666 var c = db._create(cn);667 c.ensureUniqueConstraint("a", "b");668 669 var tick = getLastLogTick();670 // use index at #1 (#0 is primary index)671 var idx = c.getIndexes()[1];672 c.dropIndex(idx);673 var entry = getLogEntries(tick, 2101)[0];674 assertTrue(2101, entry.type);675 assertEqual(c._id, entry.cid, JSON.stringify(entry));676 assertEqual(idx.id.replace(/^.*\//, ''), entry.data.id);677 },678////////////////////////////////////////////////////////////////////////////////679/// @brief test actions680////////////////////////////////////////////////////////////////////////////////681 testLoggerSaveDocument : function () {682 var c = db._create(cn);683 684 var tick = getLastLogTick();685 c.save({ "test": 1, "_key": "abc" });686 var rev = c.document("abc")._rev;687 var entry = getLogEntries(tick, 2300)[0];688 assertEqual(2300, entry.type);689 assertEqual(c._id, entry.cid, JSON.stringify(entry));690 assertEqual("abc", entry.data._key);691 assertEqual(rev, entry.data._rev);692 assertEqual(1, entry.data.test);693 tick = getLastLogTick();694 c.save({ "test": 2, "foo" : "bar", "_key": "12345" });695 rev = c.document("12345")._rev;696 entry = getLogEntries(tick, 2300)[0];697 assertEqual(2300, entry.type);698 assertEqual(c._id, entry.cid, JSON.stringify(entry));699 assertEqual("12345", entry.data._key);700 assertEqual(rev, entry.data._rev);701 assertEqual(2, entry.data.test);702 assertEqual("bar", entry.data.foo);703 try {704 c.save({ "test": 1, "_key": "12345" });705 fail();706 }707 catch (err) {708 }709 entry = getLogEntries(tick, 2300);710 assertEqual(1, entry.length);711 },712////////////////////////////////////////////////////////////////////////////////713/// @brief test actions714////////////////////////////////////////////////////////////////////////////////715 testLoggerSaveDocuments : function () {716 var c = db._create(cn);717 718 var tick = getLastLogTick();719 for (var i = 0; i < 100; ++i) {720 c.save({ "test": 1, "_key": "test" + i });721 }722 var entry = getLogEntries(tick, 2300);723 assertEqual(100, entry.length);724 },725////////////////////////////////////////////////////////////////////////////////726/// @brief test actions727////////////////////////////////////////////////////////////////////////////////728 testLoggerDeleteDocument : function () {729 var c = db._create(cn);730 c.save({ "test": 1, "_key": "abc" });731 c.save({ "test": 1, "_key": "12345" });732 var tick = getLastLogTick();733 c.remove("abc");734 var entry = getLogEntries(tick, 2302)[0];735 assertEqual(2302, entry.type);736 assertEqual(c._id, entry.cid, JSON.stringify(entry));737 assertEqual("abc", entry.data._key);738 tick = getLastLogTick();739 c.remove("12345");740 entry = getLogEntries(tick, 2302)[0];741 assertEqual(2302, entry.type);742 assertEqual(c._id, entry.cid, JSON.stringify(entry));743 assertEqual("12345", entry.data._key);744 tick = getLastLogTick();745 try {746 c.remove("12345");747 fail();748 }749 catch (err) {750 }751 entry = getLogEntries(tick, 2302);752 assertEqual(0, entry.length);753 },754////////////////////////////////////////////////////////////////////////////////755/// @brief test actions756////////////////////////////////////////////////////////////////////////////////757 testLoggerUpdateDocument : function () {758 var c = db._create(cn);759 var tick = getLastLogTick();760 c.save({ "test": 2, "_key": "abc" });761 c.save({ "test": 1, "_key": "12345" });762 c.update("abc", { "test" : 2 });763 var entry = getLogEntries(tick, 2300);764 assertEqual(2300, entry[0].type);765 assertEqual(c._id, entry[0].cid);766 assertEqual("abc", entry[0].data._key);767 assertEqual(2, entry[0].data.test);768 assertEqual(2300, entry[1].type);769 assertEqual(c._id, entry[1].cid);770 assertEqual("12345", entry[1].data._key);771 assertEqual(1, entry[1].data.test);772 tick = getLastLogTick();773 c.update("abc", { "test" : 3 });774 entry = getLogEntries(tick, 2300)[0];775 assertEqual(2300, entry.type);776 assertEqual(c._id, entry.cid, JSON.stringify(entry));777 assertEqual("abc", entry.data._key);778 assertEqual(3, entry.data.test);779 tick = getLastLogTick();780 c.update("abc", { "test" : 3 });781 c.update("12345", { "test" : 2 });782 c.update("abc", { "test" : 4 });783 entry = getLogEntries(tick, 2300);784 assertEqual(3, entry.length);785 tick = getLastLogTick();786 try {787 c.update("thefoxx", { });788 fail();789 }790 catch (err) {791 }792 entry = getLogEntries(tick, 2300);793 assertEqual(0, entry.length);794 },795////////////////////////////////////////////////////////////////////////////////796/// @brief test actions797////////////////////////////////////////////////////////////////////////////////798 testLoggerReplaceDocument : function () {799 var c = db._create(cn);800 var tick = getLastLogTick();801 c.save({ "test": 2, "_key": "abc" });802 c.save({ "test": 1, "_key": "12345" });803 c.replace("abc", { "test" : 2 });804 var entry = getLogEntries(tick, 2300);805 assertEqual(2300, entry[0].type);806 assertEqual(c._id, entry[0].cid);807 assertEqual("abc", entry[0].data._key);808 assertEqual(2, entry[0].data.test);809 assertEqual(2300, entry[1].type);810 assertEqual(c._id, entry[1].cid);811 assertEqual("12345", entry[1].data._key);812 assertEqual(1, entry[1].data.test);813 tick = getLastLogTick();814 c.replace("abc", { "test" : 3 });815 c.replace("abc", { "test" : 3 });816 c.replace("12345", { "test" : 2 });817 c.replace("abc", { "test" : 4 });818 entry = getLogEntries(tick, 2300);819 assertEqual(4, entry.length);820 tick = getLastLogTick();821 try {822 c.replace("thefoxx", { });823 fail();824 }825 catch (err) {826 }827 entry = getLogEntries(tick, 2300);828 assertEqual(0, entry.length);829 },830////////////////////////////////////////////////////////////////////////////////831/// @brief test actions832////////////////////////////////////////////////////////////////////////////////833 testLoggerSaveEdge : function () {834 var c = db._create(cn);835 var e = db._createEdgeCollection(cn2);836 var tick = getLastLogTick();837 e.save(cn + "/test1", cn + "/test2", { "test": 1, "_key": "abc" });838 var entry = getLogEntries(tick, 2300)[0];839 assertEqual(2300, entry.type);840 assertEqual(e._id, entry.cid);841 assertEqual("abc", entry.data._key);842 assertEqual(c.name() + "/test1", entry.data._from);843 assertEqual(c.name() + "/test2", entry.data._to);844 assertEqual(1, entry.data.test);845 tick = getLastLogTick();846 e.save(cn + "/test3", cn + "/test4", { "test": [ 99, false ], "_key": "12345" });847 entry = getLogEntries(tick, 2300)[0];848 assertEqual(2300, entry.type);849 assertEqual(e._id, entry.cid);850 assertEqual("12345", entry.data._key);851 assertEqual(c.name() + "/test3", entry.data._from);852 assertEqual(c.name() + "/test4", entry.data._to);853 assertEqual([ 99, false ], entry.data.test);854 tick = getLastLogTick();855 try {856 e.save();857 fail();858 }859 catch (err) {860 }861 entry = getLogEntries(tick, 2300);862 assertEqual(0, entry.length);863 },864////////////////////////////////////////////////////////////////////////////////865/// @brief test actions866////////////////////////////////////////////////////////////////////////////////867 testLoggerDeleteEdge : function () {868 db._create(cn);869 var e = db._createEdgeCollection(cn2);870 e.save(cn + "/test1", cn + "/test2", { "test": 1, "_key": "abc" });871 e.save(cn + "/test3", cn + "/test4", { "test": 1, "_key": "12345" });872 var tick = getLastLogTick();873 e.remove("abc");874 var entry = getLogEntries(tick, 2302)[0];875 assertEqual(2302, entry.type);876 assertEqual(e._id, entry.cid);877 assertEqual("abc", entry.data._key);878 e.remove("12345");879 tick = getLastLogTick();880 try {881 e.remove("12345");882 fail();883 }884 catch (err) {885 }886 entry = getLogEntries(tick, 2302);887 assertEqual(0, entry.length);888 },889////////////////////////////////////////////////////////////////////////////////890/// @brief test actions891////////////////////////////////////////////////////////////////////////////////892 testLoggerUpdateEdge : function () {893 var c = db._create(cn);894 var e = db._createEdgeCollection(cn2);895 var tick = getLastLogTick();896 e.save(cn + "/test1", cn + "/test2", { "test": 2, "_key": "abc" });897 e.save(cn + "/test3", cn + "/test4", { "test": 1, "_key": "12345" });898 e.update("abc", { "test" : 2 });899 var entry = getLogEntries(tick, 2300);900 assertEqual(2300, entry[0].type);901 assertEqual(e._id, entry[0].cid);902 assertEqual("abc", entry[0].data._key);903 assertEqual(2, entry[0].data.test);904 assertEqual(c.name() + "/test1", entry[0].data._from);905 assertEqual(c.name() + "/test2", entry[0].data._to);906 assertEqual(2300, entry[1].type);907 assertEqual(e._id, entry[1].cid);908 assertEqual("12345", entry[1].data._key);909 assertEqual(1, entry[1].data.test);910 assertEqual(c.name() + "/test3", entry[1].data._from);911 assertEqual(c.name() + "/test4", entry[1].data._to);912 tick = getLastLogTick();913 e.update("abc", { "test" : 3 });914 e.update("12345", { "test" : 2 });915 e.update("abc", { "test" : 4 });916 entry = getLogEntries(tick, 2300);917 assertEqual(3, entry.length);918 tick = getLastLogTick();919 try {920 e.update("thefoxx", { });921 fail();922 }923 catch (err) {924 }925 entry = getLogEntries(tick, 2300);926 assertEqual(0, entry.length);927 },928////////////////////////////////////////////////////////////////////////////////929/// @brief test actions930////////////////////////////////////////////////////////////////////////////////931 testLoggerReplaceEdge : function () {932 var c = db._create(cn);933 var e = db._createEdgeCollection(cn2);934 var tick = getLastLogTick();935 e.save(cn + "/test1", cn + "/test2", { "test": 2, "_key": "abc" });936 e.save(cn + "/test3", cn + "/test4", { "test": 1, "_key": "12345" });937 e.replace("abc", { _from: c.name() + "/test1", _to: c.name() + "/test2", "test" : 2 });938 var entry = getLogEntries(tick, 2300);939 assertEqual(2300, entry[0].type);940 assertEqual(e._id, entry[0].cid);941 assertEqual("abc", entry[0].data._key);942 assertEqual(2, entry[0].data.test);943 assertEqual(c.name() + "/test1", entry[0].data._from);944 assertEqual(c.name() + "/test2", entry[0].data._to);945 assertEqual(2300, entry[1].type);946 assertEqual(e._id, entry[1].cid);947 assertEqual("12345", entry[1].data._key);948 assertEqual(1, entry[1].data.test);949 assertEqual(c.name() + "/test3", entry[1].data._from);950 assertEqual(c.name() + "/test4", entry[1].data._to);951 tick = getLastLogTick();952 e.replace("abc", { _from: cn + "/test1", _to: cn + "/test2", "test" : 3 });953 e.replace("abc", { _from: cn + "/test1", _to: cn + "/test2", "test" : 3 });954 e.replace("12345", { _from: cn + "/test3", _to: cn + "/test4", "test" : 2 });955 e.replace("abc", { _from: cn + "/test1", _to: cn + "/test2", "test" : 4 });956 entry = getLogEntries(tick, 2300);957 assertEqual(4, entry.length);958 tick = getLastLogTick();959 try {960 e.replace("thefoxx", { });961 fail();962 }963 catch (err) {964 }965 entry = getLogEntries(tick, 2300);966 assertEqual(0, entry.length);967 },968////////////////////////////////////////////////////////////////////////////////969/// @brief test actions970////////////////////////////////////////////////////////////////////////////////971 testLoggerTransactionEmpty : function () {972 db._create(cn);973 var tick = getLastLogTick();974 var actual = db._executeTransaction({975 collections: {976 },977 action: function () {978 return true;979 }980 });981 assertTrue(actual);982 var entry = getLogEntries(tick, 2200);983 assertEqual(0, entry.length);984 },985////////////////////////////////////////////////////////////////////////////////986/// @brief test actions987////////////////////////////////////////////////////////////////////////////////988 testLoggerTransactionRead1 : function () {989 var c = db._create(cn);990 c.save({ "test" : 1 });991 var tick = getLastLogTick();992 var actual = db._executeTransaction({993 collections: {994 read: cn995 },996 action: function () {997 return true;998 }999 });1000 assertTrue(actual);1001 var entry = getLogEntries(tick, 2200);1002 assertEqual(0, entry.length);1003 },1004////////////////////////////////////////////////////////////////////////////////1005/// @brief test actions1006////////////////////////////////////////////////////////////////////////////////1007 testLoggerTransactionRead2 : function () {1008 var c = db._create(cn);1009 c.save({ "test" : 1, "_key": "abc" });1010 var tick = getLastLogTick();1011 var actual = db._executeTransaction({1012 collections: {1013 read: cn1014 },1015 action: function (params) {1016 var c = require("internal").db._collection(params.cn);1017 c.document("abc");1018 return true;1019 },1020 params: {1021 cn: cn1022 }1023 });1024 assertTrue(actual);1025 var entry = getLogEntries(tick, [ 2200, 2201, 2202 ]);1026 assertEqual(0, entry.length);1027 },1028////////////////////////////////////////////////////////////////////////////////1029/// @brief test actions1030////////////////////////////////////////////////////////////////////////////////1031 testLoggerTransactionRead3 : function () {1032 db._create(cn);1033 var tick = getLastLogTick();1034 try {1035 var actual = db._executeTransaction({1036 collections: {1037 read: cn1038 },1039 action: function (params) {1040 var c = require("internal").db._collection(params.cn);1041 c.save({ "foo" : "bar" });1042 return true;1043 },1044 params: {1045 cn: cn1046 }1047 });1048 actual = true;1049 fail();1050 }1051 catch (err) {1052 }1053 var entry = getLogEntries(tick, [ 2200, 2201, 2202 ]);1054 assertEqual(0, entry.length);1055 },1056////////////////////////////////////////////////////////////////////////////////1057/// @brief test actions1058////////////////////////////////////////////////////////////////////////////////1059 testLoggerTransactionWrite1 : function () {1060 db._create(cn);1061 var tick = getLastLogTick();1062 var actual = db._executeTransaction({1063 collections: {1064 write: cn1065 },1066 action: function () {1067 return true;1068 }1069 });1070 assertTrue(actual);1071 var entry = getLogEntries(tick, [ 2200, 2201, 2202 ]);1072 assertEqual(0, entry.length);1073 },1074////////////////////////////////////////////////////////////////////////////////1075/// @brief test actions1076////////////////////////////////////////////////////////////////////////////////1077 testLoggerTransactionWrite2 : function () {1078 var c = db._create(cn);1079 var tick = getLastLogTick();1080 var actual = db._executeTransaction({1081 collections: {1082 write: cn1083 },1084 action: function (params) {1085 var c = require("internal").db._collection(params.cn);1086 c.save({ "test" : 2, "_key": "abc" });1087 return true;1088 },1089 params: {1090 cn: cn1091 }1092 });1093 assertTrue(actual);1094 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300 ]);1095 assertEqual(3, entry.length);1096 assertEqual(2200, entry[0].type);1097 assertEqual(2300, entry[1].type);1098 assertEqual(2201, entry[2].type);1099 assertEqual(entry[0].tid, entry[1].tid);1100 assertEqual(entry[1].tid, entry[2].tid);1101 assertEqual(c._id, entry[1].cid);1102 assertEqual("abc", entry[1].data._key);1103 assertEqual(c._id, entry[1].cid);1104 assertEqual(2, entry[1].data.test);1105 },1106////////////////////////////////////////////////////////////////////////////////1107/// @brief test actions1108////////////////////////////////////////////////////////////////////////////////1109 testLoggerTransactionWrite3 : function () {1110 db._create(cn);1111 var tick = getLastLogTick();1112 try {1113 db._executeTransaction({1114 collections: {1115 write: cn1116 },1117 action: function (params) {1118 var c = require("internal").db._collection(params.cn);1119 c.save({ "test" : 2, "_key": "abc" });1120 throw "fail";1121 },1122 params: {1123 cn: cn1124 }1125 });1126 fail();1127 }1128 catch (err) {1129 }1130 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300 ]);1131 assertEqual(3, entry.length);1132 assertEqual(2200, entry[0].type);1133 assertEqual(2300, entry[1].type);1134 assertEqual(2202, entry[2].type);1135 assertEqual(entry[0].tid, entry[1].tid);1136 assertEqual(entry[1].tid, entry[2].tid);1137 },1138////////////////////////////////////////////////////////////////////////////////1139/// @brief test actions1140////////////////////////////////////////////////////////////////////////////////1141 testLoggerTransactionWrite4 : function () {1142 db._create(cn);1143 db._create(cn2);1144 var tick = getLastLogTick();1145 try {1146 db._executeTransaction({1147 collections: {1148 write: cn1149 },1150 action: function (params) {1151 var c2 = require("internal").db._collection(params.cn2);1152 // we're using a wrong collection here1153 c2.save({ "test" : 2, "_key": "abc" });1154 },1155 params: {1156 cn2: cn21157 }1158 });1159 fail();1160 }1161 catch (err) {1162 }1163 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300 ]);1164 assertEqual(0, entry.length);1165 },1166////////////////////////////////////////////////////////////////////////////////1167/// @brief test actions1168////////////////////////////////////////////////////////////////////////////////1169 testLoggerTransactionWrite5 : function () {1170 db._create(cn);1171 db._create(cn2);1172 var tick = getLastLogTick();1173 db._executeTransaction({1174 collections: {1175 write: [ cn, cn2 ]1176 },1177 action: function (params) {1178 var c2 = require("internal").db._collection(params.cn);1179 c2.save({ "test" : 1, "_key": "12345" });1180 c2.save({ "test" : 2, "_key": "abc" });1181 },1182 params: {1183 cn: cn1184 }1185 });1186 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300 ]);1187 assertEqual(4, entry.length);1188 assertEqual(2200, entry[0].type);1189 assertEqual(2300, entry[1].type);1190 assertEqual(2300, entry[2].type);1191 assertEqual(2201, entry[3].type);1192 assertEqual(entry[0].tid, entry[1].tid);1193 assertEqual(entry[1].tid, entry[2].tid);1194 assertEqual(entry[2].tid, entry[3].tid);1195 },1196////////////////////////////////////////////////////////////////////////////////1197/// @brief test actions1198////////////////////////////////////////////////////////////////////////////////1199 testLoggerTransactionWrite6 : function () {1200 var c1 = db._create(cn);1201 var c2 = db._create(cn2);1202 var tick = getLastLogTick();1203 db._executeTransaction({1204 collections: {1205 write: [ cn, cn2 ]1206 },1207 action: function (params) {1208 var c1 = require("internal").db._collection(params.cn);1209 var c2 = require("internal").db._collection(params.cn2);1210 c1.save({ "test" : 1, "_key": "12345" });1211 c2.save({ "test" : 2, "_key": "abc" });1212 },1213 params: {1214 cn: cn,1215 cn2: cn21216 }1217 });1218 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300 ]);1219 assertEqual(4, entry.length);1220 assertEqual(2200, entry[0].type);1221 assertEqual(2300, entry[1].type);1222 assertEqual(2300, entry[2].type);1223 assertEqual(2201, entry[3].type);1224 assertEqual(entry[0].tid, entry[1].tid);1225 assertEqual(entry[1].tid, entry[2].tid);1226 assertEqual(entry[2].tid, entry[3].tid);1227 assertEqual(c1._id, entry[1].cid);1228 assertEqual(c2._id, entry[2].cid);1229 },1230////////////////////////////////////////////////////////////////////////////////1231/// @brief test collection exclusion1232////////////////////////////////////////////////////////////////////////////////1233 testLoggerTransactionExcluded : function () {1234 var c = db._create(cn);1235 var tick = getLastLogTick();1236 db._executeTransaction({1237 collections: {1238 write: [ cn, "_users" ]1239 },1240 action: function (params) {1241 var c = require("internal").db._collection(params.cn);1242 var users = require("internal").db._collection("_users");1243 c.save({ "test" : 2, "_key": "12345" });1244 users.save({ "_key": "unittests1", "foo": false });1245 users.remove("unittests1");1246 },1247 params: {1248 cn: cn1249 }1250 });1251 var entry = getLogEntries(tick, [ 2200, 2201, 2202, 2300, 2302 ]);1252 assertEqual(5, entry.length);1253 assertEqual(2200, entry[0].type);1254 assertEqual(2300, entry[1].type);1255 assertEqual(2300, entry[2].type);1256 assertEqual(2302, entry[3].type);1257 assertEqual(2201, entry[4].type);1258 assertEqual(entry[0].tid, entry[1].tid);1259 assertEqual(entry[1].tid, entry[2].tid);1260 assertEqual(c._id, entry[1].cid);1261 }1262 };1263}1264////////////////////////////////////////////////////////////////////////////////1265/// @brief test suite...
webServiceCheck.tests.js
Source:webServiceCheck.tests.js
...39 it('should reject an invalid URL and log an error', async function () {40 const webServiceComponent = new WebServiceComponentClass(mockServiceConfigObject);41 const response = await WebServiceCheck.makeWebServiceRequest(webServiceComponent, log);42 expect(response.getActualResponseCode()).to.equal('Error: Invalid URI "some%20url"');43 expect(log.getLogEntries()[1].type).to.equal('error');44 expect(log.getLogEntries().length).to.equal(2);45 expect(log.getLogEntries()[1].message).to.contain('Error: Invalid URI "some%20url"');46 });47 it('should test a webService and return a 200', async function () {48 const webServiceComponent = new WebServiceComponentClass(mockServiceConfigObject);49 webServiceComponent.setUrl('http://bbc.co.uk');50 const response = await MockwebServiceCheck.makeValidHttpRequest(webServiceComponent, log);51 expect(response.getActualResponseCode()).to.equal(200);52 expect(log.getLogEntries()[0].type).to.equal('info');53 expect(log.getLogEntries().length).to.equal(1);54 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 200. Response time 0ms.');55 });56 it('should test a valid webService and return a 200', async function () {57 const webServiceComponent = new WebServiceComponentClass(validServiceConfigObject);58 const response = await WebServiceCheck.makeWebServiceRequest(webServiceComponent, log);59 expect(response.getActualResponseCode()).to.equal(200);60 expect(log.getLogEntries()[0].type).to.equal('info');61 expect(log.getLogEntries().length).to.equal(2);62 expect(log.getLogEntries()[1].message).to.contain('Called Valid Check check. Response code 200.');63 });64 it('should attempt to check a webService but return a 404', async function () {65 const webServiceComponent = new WebServiceComponentClass(mockServiceConfigObject);66 webServiceComponent.setUrl('http://bbc.co.uk');67 webServiceComponent.setExpectedResponseCode(404);68 const response = await MockwebServiceCheck.makePageNotFoundHttpRequest(webServiceComponent, log);69 expect(response.getActualResponseCode()).to.equal(404);70 expect(log.getLogEntries()[0].type).to.equal('info');71 expect(log.getLogEntries().length).to.equal(1);72 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 404. Response time 0ms.');73 });74 it('should attempt to check a webService but return a 500', async function () {75 const webServiceComponent = new WebServiceComponentClass(mockServiceConfigObject);76 webServiceComponent.setUrl('http://bbc.co.uk');77 webServiceComponent.setExpectedResponseCode(500);78 const response = await MockwebServiceCheck.makeServerErrorHttpRequest(webServiceComponent, log);79 expect(response.getActualResponseCode()).to.equal(500);80 expect(log.getLogEntries()[0].type).to.equal('info');81 expect(log.getLogEntries().length).to.equal(1);82 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 500');83 });...
websiteCheck.tests.js
Source:websiteCheck.tests.js
...31 it('should reject an invalid URL and log an error', async function () {32 const websiteComponent = new WebsiteComponentClass(mockServiceConfigObject);33 const response = await WebsiteCheck.makeHttpRequest(websiteComponent, log);34 expect(response.getActualResponseCode()).to.equal('Error: Invalid URI "some%20url"');35 expect(log.getLogEntries()[1].type).to.equal('error');36 expect(log.getLogEntries().length).to.equal(2);37 expect(log.getLogEntries()[1].message).to.contain('Error: Invalid URI "some%20url"');38 });39 it('should test a website and return a 200', async function () {40 const websiteComponent = new WebsiteComponentClass(mockServiceConfigObject);41 websiteComponent.setUrl('http://bbc.co.uk');42 const response = await MockWebsiteCheck.makeValidHttpRequest(websiteComponent, log);43 expect(response.getActualResponseCode()).to.equal(200);44 expect(log.getLogEntries()[0].type).to.equal('info');45 expect(log.getLogEntries().length).to.equal(1);46 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 200. Response time 0ms.');47 });48 it('should test a real website and return a 200', async function () {49 const websiteComponent = new WebsiteComponentClass(validServiceConfigObject);50 const response = await WebsiteCheck.makeHttpRequest(websiteComponent, log);51 expect(response.getActualResponseCode()).to.equal(200);52 expect(log.getLogEntries()[0].type).to.equal('info');53 expect(log.getLogEntries().length).to.equal(2);54 expect(log.getLogEntries()[1].message).to.contain('Called Name of the check check. Response code 200.');55 });56 it('should attempt to check a website but return a 404', async function () {57 const websiteComponent = new WebsiteComponentClass(mockServiceConfigObject);58 websiteComponent.setUrl('http://bbc.co.uk');59 websiteComponent.setExpectedResponseCode(404);60 const response = await MockWebsiteCheck.makePageNotFoundHttpRequest(websiteComponent, log);61 expect(response.getActualResponseCode()).to.equal(404);62 expect(log.getLogEntries()[0].type).to.equal('info');63 expect(log.getLogEntries().length).to.equal(1);64 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 404. Response time 0ms.');65 });66 it('should attempt to check a website but return a 500', async function () {67 const websiteComponent = new WebsiteComponentClass(mockServiceConfigObject);68 websiteComponent.setUrl('http://bbc.co.uk');69 websiteComponent.setExpectedResponseCode(500);70 const response = await MockWebsiteCheck.makeServerErrorHttpRequest(websiteComponent, log);71 expect(response.getActualResponseCode()).to.equal(500);72 expect(log.getLogEntries()[0].type).to.equal('info');73 expect(log.getLogEntries().length).to.equal(1);74 expect(log.getLogEntries()[0].message).to.contain('Called http://bbc.co.uk. Response code 500');75 });...
Using AI Code Generation
1const http = require('http');2const options = {3};4const req = http.request(options, (res) => {5 console.log(`STATUS: ${res.statusCode}`);6 console.log(`HEADERS: ${JSON.stringify(res.headers)}`);7 res.setEncoding('utf8');8 res.on('data', (chunk) => {9 console.log(`BODY: ${chunk}`);10 });11 res.on('end', () => {12 console.log('No more data in response.');13 });14});15req.on('error', (e) => {16 console.log(`problem with request: ${e.message}`);17});18req.end();19HEADERS: {"content-type":"application/json","access-control-allow-origin":"*","access-control-allow-headers":"X-Requested-With, Content-Type, Accept, Origin, Authorization","access-control-allow-methods":"GET, POST, PUT, DELETE, OPTIONS","access-control-expose-headers":"Location","access-control-max-age":"600","connection":"close","date":"Fri, 19 Jul 2019 12:26:31 GMT","transfer-encoding":"chunked"}20BODY: [{"protocol":"http","port":3000,"numberOfRequests":1,"requests":[{"timestamp":"2019-07-19T12:26:31.893Z","requestFrom":"::1","method":"GET","path":"/","query":{},"headers":{"host":"localhost:3000","connection":"keep-alive","cache-control":"max-age=0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,hi;q=0.8"}},{"timestamp":"2019-07-19T12:26
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const imposterPort = 3000;4const protocol = 'http';5 {6 {7 equals: {8 }9 }10 {11 is: {12 }13 }14 }15];16const imposter = {17};18mb.create(port, imposter).then(() => {19 console.log('Imposter created successfully');20 return mb.getLogEntries(port, imposterPort);21}).then((logEntries) => {22 console.log('Log entries: ', logEntries);23 return mb.delete(port, imposterPort);24}).then(() => {25 console.log('Imposter deleted successfully');26}).catch((error) => {27 console.error('Error: ', error);28});29 {30 "request": {31 "headers": {32 },33 "query": {},34 },35 "response": {36 "headers": {37 "content-type": "application/json; charset=utf-8"38 },39 },40 }41const mb = require('mountebank');42const port = 2525;43const imposterPort = 3000;44const protocol = 'http';45 {46 {47 equals: {48 }49 }50 {51 is: {52 }53 }
Using AI Code Generation
1var mountebank = require('mountebank');2var mb = mountebank.create({ port: 2525, allowInjection: true });3mb.get('/imposters', function (err, imposters) {4 console.log(imposters);5});6mb.get('/imposters/3', function (err, imposters) {7 console.log(imposters);8});9mb.get('/imposters/3/logs', function (err, imposters) {10 console.log(imposters);11});12var mountebank = require('mountebank');13var mb = mountebank.create({ port: 2525, allowInjection: true });14mb.get('/imposters', function (err, imposters) {15 console.log(imposters);16});17mb.get('/imposters/3', function (err, imposters) {18 console.log(imposters);19});20mb.get('/imposters/3/logs', function (err, imposters) {21 console.log(imposters);22});23var mountebank = require('mountebank');24var mb = mountebank.create({ port: 2525, allowInjection: true });25mb.get('/imposters', function (err, imposters) {26 console.log(imposters);27});28mb.get('/imposters/3', function (err, imposters) {29 console.log(imposters);30});31mb.get('/imposters/3/logs', function (err, imposters) {32 console.log(imposters);33});34var mountebank = require('mountebank');35var mb = mountebank.create({ port: 2525, allowInjection: true });36mb.get('/imposters', function (err, imposters) {37 console.log(imposters);38});39mb.get('/imposters/3', function (err, imposters) {40 console.log(imposters);41});42mb.get('/imposters/3/logs', function (err, imposters) {43 console.log(imposters);44});45var mountebank = require('mountebank');46var mb = mountebank.create({ port: 2525, allowInjection: true });
Using AI Code Generation
1var mb = require('mountebank');2var imposters = mb.getImposters();3console.log(imposters);4var logEntries = mb.getLogEntries();5console.log(logEntries);6var mb = require('mountebank');7var imposters = mb.getImposters();8console.log(imposters);9var mb = require('mountebank');10var imposter = mb.createImposter(4545, 'http');11console.log(imposter);12var mb = require('mountebank');13var imposter = mb.createImposter(4545, 'http');14console.log(imposter);15var imposter = mb.getImposter(4545);16console.log(imposter);17var mb = require('mountebank');18var imposter = mb.createImposter(4545, 'http');19console.log(imposter);20var imposter = mb.deleteImposter(4545);21console.log(imposter);22var mb = require('mountebank');23var imposter = mb.createImposter(4545, 'http');24console.log(imposter);25var imposter = mb.deleteAllImposters();26console.log(imposter);27var mb = require('mountebank');28var imposter = mb.createImposter(4545, 'http');29console.log(imposter);30var stub = mb.addStub(4545, {responses: [{is: {body: 'Hello World'}}]});31console.log(stub);32var mb = require('mountebank');33var imposter = mb.createImposter(4545, 'http');34console.log(imposter);35var stub = mb.addStub(4545, {responses: [{is: {body: 'Hello World'}}]});36console.log(stub);37var stubs = mb.getStubs(4545);38console.log(stubs);39var mb = require('mountebank');40var imposter = mb.createImposter(4545, 'http');41console.log(imposter);
Using AI Code Generation
1var mb = require('mountebank-helper');2var mbHelper = new mb('localhost', 2525);3mbHelper.getLogEntries().then(function (entries) {4 console.log(entries);5});6var Q = require('q');7var request = require('request');8function MountebankHelper(host, port) {9 this.host = host;10 this.port = port;11}12MountebankHelper.prototype.getLogEntries = function () {13 var deferred = Q.defer();14 var options = {15 };16 request(options, function (error, response, body) {17 if (error) {18 deferred.reject(error);19 } else {20 deferred.resolve(body);21 }22 });23 return deferred.promise;24};25module.exports = MountebankHelper;
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var imposterPort = 4545;4var imposterName = 'imposter';5var imposters = {6 {7 {8 is: {9 headers: {10 },11 }12 }13 }14};15mb.create(port).then(function (mbServer) {16 mbServer.createImposter(imposters, imposterName);17 mbServer.getLogEntries(imposterName).then(function (logEntries) {18 console.log(logEntries);19 });20});
Using AI Code Generation
1var mb = require('mountebank');2var options = {3};4mb.getLogs(options, function (error, logs) {5 if (error) {6 console.log(error);7 } else {8 console.log(logs);9 }10});
Using AI Code Generation
1var mb = require('mountebank');2mb.getImposter(4545, function (error, imposter) {3 if (error) {4 console.error(error);5 } else {6 console.log(imposter.requests);7 }8});
Using AI Code Generation
1const mbHelper = require('./mbHelper');2const mb = mbHelper.mb;3mb.getLogs().then(data => {4 console.log(data);5});6const mb = require('mountebank');7const mbHelper = {8 mb: mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'})9};10module.exports = mbHelper;
Using AI Code Generation
1var mb = require('mountebank');2var imposter = mb.create({ port: 2525, name: 'test' });3imposter.addStub({4 { is: { body: 'Hello, World!' } }5});6imposter.post('/hello', function (request, response) {7 response.end('Hello, World!');8});9imposter.start()10 .then(function () {11 return imposter.get('/hello');12 })13 .then(function () {14 return imposter.getLogEntries();15 })16 .then(function (logEntries) {17 console.log(logEntries.requests);18 console.log(logEntries.stubs);19 })20 .finally(function () {21 imposter.stop();22 });23var mb = require('mountebank');24var imposter = mb.create({ port: 2525, name: 'test' });25imposter.addStub({26 { is: { body: 'Hello, World!' } }27});28imposter.post('/hello', function (request, response) {29 response.end('Hello, World!');30});31imposter.start()32 .then(function () {33 return imposter.get('/hello');34 })35 .then(function () {36 return imposter.getLogEntries();37 })38 .then(function (logEntries) {39 console.log(logEntries.requests);40 console.log(logEntries.stubs);41 })42 .finally(function () {43 imposter.stop();44 });
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!