How to use dryRun method in mountebank

Best JavaScript code snippet using mountebank

main.js

Source:main.js Github

copy

Full Screen

1#!/usr/bin/env node2const yargs = require('yargs')3const AWS = require('aws-sdk')4const bunyan = require('bunyan')5const Promise = require('bluebird')6const _ = require('lodash')7let log8const efs = new AWS.EFS({ apiVersion: '2015-02-01', region: process.env.AWS_REGION })9const ec2 = new AWS.EC2({ apiVersion: '2016-11-15' })10const elb = new AWS.ELBv2({ apiVersion: '2015-12-01' });11const elbClassic = new AWS.ELB();12const yargsFunc = (yargs) => {13 //yargs.positional('vpc-id', { describe: 'ID of the VPC', default: null })14}15yargs16 .command('delete [vpc-id]', 'Delete the VPC and all dependencies', yargsFunc, async (argv) => {17 const stream = argv.logToStdout ? process.stdout : process.stderr18 log = bunyan.createLogger({ name: "delete-vpc", level: argv.logLevel, stream })19 argv.dryRun = false;20 await deleteEC2Instances(argv.vpcId, argv.dryRun) // Remove Instances21 await deleteELBs(argv.vpcId, argv.dryRun) // Remove Load Balancers22 await deleteELBsClassic(argv.vpcId, argv.dryRun) // Remove Load Balancers23 await deleteEFS(argv.vpcId, argv.dryRun) // Remove EFS volumes24 await deleteNATGateways(argv.vpcId, argv.dryRun) // Remove NAT Gateways25 await deleteNetworkInterfaces(argv.vpcId, argv.dryRun) // Remove Network Interfaces 26 await deleteSecurityGroups(argv.vpcId, argv.dryRun) // Remove Instances27 await deleteInternetGateways(argv.vpcId, argv.dryRun) // Remove Internet Gateways28 await deleteSubnets(argv.vpcId, argv.dryRun)29 await deleteRouteTables(argv.vpcId, argv.dryRun)30 await deleteVPCEndpoints(argv.vpcId, argv.dryRun)31 await deleteVPC(argv.vpcId, argv.dryRun) // Remove VPC32 //await releaseEIPs(argv.vpcId, argv.dryRun) // Remove Instances33 //console.log('VPC Deleted');34 })35 .option('log-level', { describe: 'Log level (debug, trace, info, warn, error)', default: 'info' })36 .option('log-to-stdout', { describe: 'Output logs to STDOUT instead of STDERR', default: true })37 .argv38async function releaseEIPs(VpcId, DryRun) {39 console.log('Releasing EIPs instances .... ')40 const params = {41 Filters: [42 {43 Name: 'domain',44 Values: [ 'vpc' ]45 }]46 };47 const response = await Promise.fromCallback(cb => ec2.describeAddresses(params, cb))48 await Promise.map(response.Addresses, async (item) => {49 const allocationID = item.AllocationId50 const releaseParams = { DryRun, AllocationId:allocationID }51 return $(ec2, 'releaseAddress', releaseParams, { allowedErrorCodes: ['OperationNotPermitted','InvalidAttachmentID.NotFound'], retryErrorCodes: ['AuthFailure','UnsupportedOperation','InvalidParameterValue','OperationalError'] }) 52 })53}54 55async function deleteEC2Instances(vpcId, DryRun) {56 console.log('Deleting EC2 instances .... ')57 this.log = log.child({ methods: 'deleteEC2Instances', vpcId });58 this.log.trace('Start deleting EC2 instances')59 const filterParams = {60 Filters: [61 {62 Name: 'vpc-id',63 Values: [ vpcId ]64 }]65 }66 this.log.trace('Filter Params', { filterParams })67 const reservations = await Promise.fromCallback(cb => ec2.describeInstances(filterParams, cb))68 const instancesMap = reservations.Reservations.reduce((accumulator, current) => {69 current.Instances.forEach(i => { accumulator[i.InstanceId] = i })70 return accumulator71 }, {})72 const Ids = Object.keys(instancesMap)73 this.log.trace('Instances', { Ids })74 if (Ids.length === 0) {75 this.log.trace('No instances to delete')76 return []77 }78 const deleteParams = { InstanceIds:Ids, DryRun }79 this.log.trace('DeleteParams', { deleteParams })80 return $(ec2, 'terminateInstances', deleteParams)81}82async function deleteELBs(vpcId, DryRun) {83 console.log('Deleting ELBs non-classic instances .... ')84 this.log = log.child({ methods: 'deleteELBs', vpcId });85 this.log.trace('Start')86 const elbs = await Promise.fromCallback(cb => elb.describeLoadBalancers({}, cb))87 const elbsInVPC = elbs.LoadBalancers.filter(x => x.VpcId === vpcId) 88 89 return await Promise.map(elbsInVPC, async (elbInstance) => {90 const deleteParams = {91 LoadBalancerArn: elbInstance.LoadBalancerArn92 }93 94 if (DryRun) {95 this.log.info('Dry run. Deleteing ELB', { name: elbInstance.LoadBalancerName })96 return97 }98 return await $(elb, 'deleteLoadBalancer', deleteParams)99 })100}101async function deleteELBsClassic(vpcId, DryRun) {102 console.log('Deleting ELBs classic instances .... ')103 this.log = log.child({ methods: 'deleteELBs', vpcId });104 this.log.trace('Start')105 const elbs = await Promise.fromCallback(cb => elbClassic.describeLoadBalancers({}, cb))106 const elbsInVPC = elbs.LoadBalancerDescriptions.filter(x => x.VPCId === vpcId) 107 108 109 return await Promise.map(elbsInVPC, async (elbInstance) => {110 const deleteParams = {111 LoadBalancerName: elbInstance.LoadBalancerName112 }113 114 if (DryRun) {115 this.log.info('Dry run. Deleteing ELB', { name: elbInstance.LoadBalancerName })116 return117 }118 return await $(elbClassic, 'deleteLoadBalancer', deleteParams)119 })120}121async function deleteVPCEndpoints(VpcId, DryRun) {122 console.log('Deleting VPC endpoint instances .... ')123 this.log = log.child({ methods: 'deleteVpcEndpoints', VpcId, DryRun });124 const params = {125 Filters: [126 {127 Name: 'vpc-id',128 Values: [ VpcId ]129 }]130 };131 const response = await Promise.fromCallback(cb => ec2.describeVpcEndpoints(params, cb))132 133 const endPointIds = response.VpcEndpoints.map(x => x.VpcEndpointId)134 135 await Promise.map(endPointIds, async (id) => {136 const params = { VpcEndpointIds:[id], DryRun };137 //const detachParams = Object.assign({}, params, { VpcId })138 //await $(ec2, 'deleteVpcEndpoints', detachParams)139 await $(ec2, 'deleteVpcEndpoints', params)140 })141 this.log.trace(`endPointIds succesfuly deleted DryRun: ${DryRun}`)142 return endPointIds143}144async function deleteInternetGateways(VpcId, DryRun) {145 console.log('Deleting IG instances .... ')146 this.log = log.child({ methods: 'deleteInternetGateways', VpcId, DryRun });147 this.log.trace('Start deleting internet gateways')148 const params = {149 Filters: [150 {151 Name: "attachment.vpc-id",152 Values: [ VpcId ]153 }154 ]155 };156 const response = await Promise.fromCallback(cb => ec2.describeInternetGateways(params, cb))157 const InternetGatewayIds = response.InternetGateways.map(x => x.InternetGatewayId)158 this.log.trace('Internet Gateway Ids', { InternetGatewayIds })159 await Promise.map(InternetGatewayIds, async (id) => {160 const params = { InternetGatewayId:id, DryRun };161 const detachParams = Object.assign({}, params, { VpcId })162 await $(ec2, 'detachInternetGateway', detachParams)163 await $(ec2, 'deleteInternetGateway', params)164 })165 this.log.trace(`InternetGateways succesfuly deleted DryRun: ${DryRun}`)166 return InternetGatewayIds167}168async function deleteEFS (vpcId, DryRun) {169 console.log('Deleting EFS instances .... ')170 this.log = log.child({ methods: 'deleteEFS', vpcId, DryRun });171 this.log.trace('Start deleting EFS Filesystems')172 const response = await Promise.fromCallback(cb => efs.describeFileSystems({}, cb))173 const fileSystemIds = response.FileSystems.map(x => x.FileSystemId)174 this.log.trace('fileSystemIds', { fileSystemIds })175 const mountTargets = await Promise.reduce(fileSystemIds, async (memo, FileSystemId) => {176 const params = { FileSystemId }177 const response = await Promise.fromCallback(cb => efs.describeMountTargets(params, cb))178 this.log.trace('memoLength', { length: memo.length, super: response.MountTargets.length })179 return [].concat(memo).concat(response.MountTargets)180 }, [])181 const subnetIds = await getSubnetIds(vpcId)182 this.log.trace('mountTargets', { mountTargets })183 this.log.trace('subnetIds', { subnetIds })184 const mountTargetsToBeDeleted = mountTargets.filter(x => {185 this.log.trace('SubnetId', { SubnetId: x.SubnetId })186 return subnetIds.includes(x.SubnetId)187 })188 this.log.trace('mountTargetsToBeDeleted', { mountTargetsToBeDeleted })189 const fileSystemsToBeDeleted = _.uniq(mountTargetsToBeDeleted.map(x => x.FileSystemId))190 this.log.trace('fileSystemsToBeDeleted', { fileSystemsToBeDeleted })191 await Promise.map(mountTargetsToBeDeleted, async (mountTarget) => {192 const params = { MountTargetId: mountTarget.MountTargetId }193 this.log.trace('Delete File System', { params })194 return await $(efs, 'deleteMountTarget', params)195 })196 // NOTE: This will delete any EFS with a mount target in the subet. Very greedy197 // Ideally it would only delete EFS with all mount targets in a VPC198 await Promise.delay(3000)199 await Promise.map(fileSystemsToBeDeleted, async (FileSystemId) => {200 const params = { FileSystemId }201 this.log.trace('Delete File System', { FileSystemId })202 return await $(efs, 'deleteFileSystem', params, { retryErrorCodes: 'FileSystemInUse', retries: 10 })203 })204}205async function deleteNATGateways(vpcId, DryRun) {206 console.log('Deleting NAT Gateways instances .... ')207 this.log = log.child({ methods: 'deleteNATGateways', vpcId, DryRun });208 this.log.trace('Start deleting NAT Gateways')209 const params = {210 Filter: [211 {212 Name: "vpc-id",213 Values: [ vpcId ]214 }215 ]216 };217 const response = await Promise.fromCallback(cb => ec2.describeNatGateways(params, cb))218 const NatGatewayIds = response.NatGateways.map(x => x.NatGatewayId)219 return await Promise.map(NatGatewayIds, async (id) => {220 const params = { NatGatewayId:id };221 await $(ec2, 'deleteNatGateway', params)222 })223}224async function getSubnetIds (vpcId) {225 const params = {226 Filters: [{227 Name: "vpc-id",228 Values: [ vpcId ]229 }]230 };231 const subnetResponse = await Promise.fromCallback(cb => ec2.describeSubnets(params, cb))232 return subnetResponse.Subnets.map(x => x.SubnetId)233}234async function deleteSubnets (id, DryRun) {235 console.log('Deleting subnets instances .... ')236 this.log = log.child({ methods: 'deleteSubnets', id, DryRun });237 this.log.trace('Start deleting subnets')238 const params = { VpcId: id, DryRun };239 const subnetIds = await getSubnetIds(id)240 this.log.trace('SubnetIds', { subnetIds })241 await Promise.delay(3000)242 await Promise.map(subnetIds, async (SubId) => {243 const params = {SubnetId:SubId, DryRun}244 this.log.trace('Deleting subnet', { SubId })245 await $(ec2, 'deleteSubnet', params, { retryErrorCodes: 'DependencyViolation' })246 })247}248async function deleteVPC (id, DryRun) {249 console.log('Finallay, deleting VPC instances .... ')250 this.log = log.child({ methods: 'deleteVPC', VpcId: id || 'nothing', DryRun });251 this.log.trace('Start deleting VPC')252 const params = { VpcId: id, DryRun };253 await $(ec2, 'deleteVpc', params, { allowedErrorCodes: 'InvalidVpcID.NotFound' })254 //this.log.info('VPC Deleted')255}256async function deleteSecurityGroups (vpcId, DryRun) {257 var params = {258 DryRun,259 Filters: [{260 Name: 'vpc-id',261 Values: [ vpcId ]262 }]263 }264 const securityGroups = (await Promise.fromCallback(cb => ec2.describeSecurityGroups(params, cb))).SecurityGroups;265 this.log.trace('Security Groups', { securityGroups })266 await Promise.mapSeries(securityGroups, async (securityGroup) => {267 this.log.trace('Security group', { securityGroup, })268 await Promise.mapSeries(securityGroup.IpPermissions, async (ruleUnfiltered) => {269 const rule = {}270 rule.GroupId = securityGroup.GroupId271 if (!_.isEmpty(ruleUnfiltered.IpRanges)) {272 const ipRange = ruleUnfiltered.IpRanges[0]273 rule.IpProtocol = ruleUnfiltered.IpProtocol274 rule.FromPort = ruleUnfiltered.FromPort275 rule.ToPort = ruleUnfiltered.ToPort276 rule.CidrIp = ipRange.CidrIp277 }278 if (!_.isEmpty(ruleUnfiltered.UserIdGroupPairs)) {279 rule.IpPermissions = [ _.pick(ruleUnfiltered, ['IpProtocol', 'UserIdGroupPairs', 'FromPort', 'ToPort']) ]280 }281 this.log.trace('Delete Ingress Rule', { rule, ruleUnfiltered })282 await $(ec2, 'revokeSecurityGroupIngress', rule)283 })284 return285 })286 const sgIds = securityGroups.filter(x => x.GroupName !== 'default').map(x => x.GroupId)287 this.log.trace('Security Group Ids', { sgIds })288 await Promise.delay(1000)289 await Promise.map(sgIds, async function (id) {290 const params = { GroupId:id, DryRun }291 return await $(ec2, 'deleteSecurityGroup', params)292 })293}294async function deleteNetworkInterfaces (VpcId, DryRun) {295 this.log = log.child({ methods: 'deleteNetworkInterfaces', VpcId });296 const queryParams = {297 DryRun,298 Filters: [299 {300 Name: 'vpc-id',301 Values: [ VpcId ]302 }303 ]304 };305 const response = await Promise.fromCallback(cb => ec2.describeNetworkInterfaces(queryParams, cb))306 const networkInterfaceIds = response.NetworkInterfaces.map(x => x.NetworkInterfaceId)307 const networkInterfaceAttachmentIds = response.NetworkInterfaces.map(x => _.get(x, 'Attachment.AttachmentId')).filter(x => !!x)308 await Promise.map(networkInterfaceAttachmentIds, async (id) => {309 const detachParams = { AttachmentId:id, Force: true, DryRun }310 await $(ec2, 'detachNetworkInterface', detachParams, { allowedErrorCodes: ['OperationNotPermitted','InvalidAttachmentID.NotFound'], retryErrorCodes: ['AuthFailure','UnsupportedOperation','InvalidParameterValue','OperationalError'] })311 })312 await Promise.map(networkInterfaceIds, async (id) => {313 const deleteParams = { DryRun, NetworkInterfaceId:id }314 return $(ec2, 'deleteNetworkInterface', deleteParams, { allowedErrorCodes: 'InvalidNetworkInterfaceID.NotFound', retryErrorCodes: ['AuthFailure','UnsupportedOperation','InvalidParameterValue','OperationalError'] })315 })316}317async function deleteRouteTables (VpcId, DryRun) {318 const queryParams = {319 DryRun,320 Filters: [321 {322 Name: 'vpc-id',323 Values: [ VpcId ]324 },325 ]326 }327 const response = await Promise.fromCallback(cb => ec2.describeRouteTables(queryParams, cb))328 // TODO: This should filter out the default route table329 //const routeTableIds = response.RouteTables.filter(x => ((typeof x.Associations[0] !== 'undefined') && !x.Associations[0].Main)).map(x => x.RouteTableId)330 const routeTableIds = response.RouteTables.map(x => x.RouteTableId)331 return await Promise.map(routeTableIds, async (id) => {332 const query = { RouteTableId: id, DryRun } 333 return $(ec2, 'deleteRouteTable', query,{ allowedErrorCodes: 'DependencyViolation' } )334 })335}336async function $(classInstance, methodName, query, opts = {}) {337 this.log = log.child({ methods: '$', endpoint: classInstance.endpoint.host, methodName, query, opts });338 const className = classInstance.endpoint.host.split('.')[0]339 let result340 try {341 result = await Promise.fromCallback(cb => classInstance[methodName](query, cb))342 } catch (err) {343 if (opts.retryErrorCodes && opts.retryErrorCodes.includes(err.code)) {344 opts.retries = ((_.isNumber(opts.retries) ? opts.retries : 20) - 1)345 if (opts.retries <= 0) {346 this.log.error('No retries left', { retries: opts.retries, errorCode: err.code })347 return348 //throw err349 }350 this.log.trace('Retrying', { retries: opts.retries, errorCode: err.code })351 await Promise.delay(opts.retryDelay || 5000)352 return $(classInstance, methodName, query, opts)353 }354 if (opts.allowedErrorCodes && opts.allowedErrorCodes.includes(err.code)) {355 this.log.trace('Allowed Error', { errorCode: err.code })356 return 357 }358 if (opts.unHandledErrorCodes && opts.unHandledErrorCodes.includes(err.code)) {359 this.log.error('Unhandled Error. This error is unhanlded and cannot be fixed by re-running this command. Log in to the AWS console and check what other resources are tied this resource.', { errorCode: err.code })360 throw err361 }362 this.log.error(`Error executing ${className}.${methodName}`, { errorCode: err.code })363 throw err364 }365 return result...

Full Screen

Full Screen

cleanup.ts

Source:cleanup.ts Github

copy

Full Screen

1import { BonusDocumentDbClient } from "./io-bonus-db";2const cleanUpDb = async ({3 dbClient,4 familyUIDs,5 fiscalCodes,6 bonuses,7 dryRun8}: {9 dbClient: BonusDocumentDbClient;10 familyUIDs: readonly string[];11 fiscalCodes: readonly string[];12 bonuses: readonly string[];13 dryRun: boolean;14}): Promise<ReadonlyArray<readonly [string, boolean]>> => {15 const executeOrDryRun = async (16 fn: () => Promise<void>,17 label: string18 ): Promise<readonly [string, boolean]> => {19 if (dryRun) {20 return [label, true];21 }22 return fn()23 .then(_ => true)24 .catch(_ => false)25 .then(result => [label, result]);26 };27 const operations: ReadonlyArray<Promise<readonly [string, boolean]>> = [28 // eligibility checks29 ...fiscalCodes.map(fiscalCode =>30 executeOrDryRun(31 () => dbClient.deleteEligibilityCheck(fiscalCode),32 `DELETE EligibilityCheck for ${fiscalCode} (dryRun=${dryRun})`33 )34 ),35 // bonus activation36 ...bonuses.map(bonus =>37 executeOrDryRun(38 () => dbClient.deleteBonusActivation(bonus),39 `DELETE BonusActivation for ${bonus} (dryRun=${dryRun})`40 )41 ),42 // user bonus43 ...bonuses.map(bonus =>44 executeOrDryRun(45 () => dbClient.deleteUserBonus(bonus),46 `DELETE UserBonus for ${bonus} (dryRun=${dryRun})`47 )48 ),49 // bonus processing50 ...bonuses.map(bonus =>51 executeOrDryRun(52 () => dbClient.deleteBonusProcessing(bonus),53 `DELETE BonusProcessing for ${bonus} (dryRun=${dryRun})`54 )55 ),56 // bonus lease57 ...familyUIDs.map(familyUID =>58 executeOrDryRun(59 () => dbClient.deleteBonusLease(familyUID),60 `DELETE BonusLease for ${familyUID} (dryRun=${dryRun})`61 )62 )63 ];64 return Promise.all(operations);65};66export interface ITestingSession {67 cleanData: (68 // tslint:disable-next-line: bool-param-default69 dryRun?: boolean70 ) => Promise<ReadonlyArray<readonly [string, boolean]>>;71 registerFiscalCode: (fiscalCode: string) => void;72 registerBonus: (bonus: string) => void;73 registerFamilyUID: (familyUID: string) => void;74}75export const createTestingSession = (76 dbClient: BonusDocumentDbClient77): ITestingSession => {78 const data = {79 bonuses: new Set<string>(),80 familyUIDs: new Set<string>(),81 fiscalCodes: new Set<string>()82 };83 return {84 async cleanData(85 dryRun = false86 ): Promise<ReadonlyArray<readonly [string, boolean]>> {87 const cleanReport = await cleanUpDb({88 bonuses: [...data.bonuses],89 dbClient,90 dryRun,91 familyUIDs: [...data.familyUIDs],92 fiscalCodes: [...data.fiscalCodes]93 }).catch(err => {94 console.error("cleanup general failure", err);95 return [];96 });97 data.bonuses.clear();98 data.fiscalCodes.clear();99 data.familyUIDs.clear();100 return cleanReport;101 },102 registerFiscalCode(fiscalCode: string): void {103 data.fiscalCodes.add(fiscalCode);104 },105 registerBonus(bonus: string): void {106 data.bonuses.add(bonus);107 },108 registerFamilyUID(familyUID: string): void {109 data.familyUIDs.add(familyUID);110 }111 };112};113export const printCleanReport = (114 cleanReport: ReadonlyArray<readonly [string, boolean]>115) => {116 cleanReport.forEach(([log, result]) => {117 if (result) {118 console.log(`cleanup success ${log}`);119 } else {120 console.error(`cleanup failure ${log}`);121 }122 });...

Full Screen

Full Screen

doPost.js

Source:doPost.js Github

copy

Full Screen

1'use strict';2const URL = 'https://api.zoined.com/';3const rp = require('request-promise');4const constants = require('./constants');5const postData = async(zoinedKey, dataType, dataValue) => {6 let uri = URL;7 switch (dataType) {8 case constants.SUPPLIERS:9 uri += 'suppliers?dryRun=false';10 break;11 case constants.SALES:12 uri += 'sales?dryRun=false';13 break;14 case constants.CAMPAIGN:15 uri += 'campaigns?dryRun=false';16 break;17 case constants.CAMPAIGNPRODUCTS:18 uri += 'campaignProducts?dryRun=false';19 break;20 case constants.DEPARTMENTS:21 uri += 'departments?dryRun=false';22 break;23 case constants.BUDGETS:24 uri += 'budgets?dryRun=false';25 break;26 case constants.PRODUCTS:27 uri += 'products?dryRun=false';28 break;29 case constants.CUSTOMERS:30 uri += 'customers?dryRun=false';31 break;32 case constants.ORGANISATIONS:33 uri += 'organisations?dryRun=false';34 break;35 case constants.SALESPERSON:36 uri += 'salespersons?dryRun=false';37 break;38 case constants.CURRENCYRATES:39 uri += 'currencyRates?dryRun=false';40 break;41 case constants.INVENTORYSNAPSHOTS:42 uri += 'inventorySnapshots?dryRun=false';43 break;44 case constants.INVENTORYTRANSACTIONS:45 uri += 'inventoryTransactions?dryRun=false';46 break;47 case constants.FLATHIERACHIES:48 uri += 'flatHierarchies?dryRun=false';49 break;50 case constants.PRODUCTHIERACHIES:51 uri += 'productHierarchies?dryRun=false';52 break;53 case constants.REBATECODES:54 uri += 'rebateCodes?dryRun=false';55 break;56 case constants.SALESSUMMARY:57 uri += 'salesSummaries?dryRun=false';58 break;59 case constants.VISITORS:60 uri += 'visitors?dryRun=false';61 break;62 case constants.VISTORDEMOGRAPHICS:63 uri += 'visitorDemographics?dryRun=false';64 break;65 case constants.IDMAPPING:66 uri += 'idMapping?dryRun=false';67 break;68 case constants.FEEDBACK:69 uri += 'customerFeedbacks?dryRun=false';70 break;71 case constants.SALESBUDGETS:72 case constants.ATVBUDGETS:73 case constants.UPTBUDGETS:74 uri += 'budgets/budget?dryRun=false';75 break;76 }77 let postOptions = {78 method: 'POST',79 uri: uri,80 body: JSON.stringify(dataValue),81 auth: {82 'bearer': zoinedKey83 },84 headers: {85 'content-type': 'application/json'86 }87 };88 return await rp(postOptions);89};...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1'use strict';2/* eslint-env jest */3/* eslint-disable global-require */4afterEach(() => {5 delete process.env.DRY_RUN;6});7describe('environment', () => {8 function expectEnv(env, active) {9 if (env != null) {10 process.env.DRY_RUN = env;11 }12 jest.resetModules();13 const dryrun = require('./index');14 expect(dryrun.isDryRun()).toBe(active);15 expect(dryrun.shouldPerform()).toBe(!active);16 }17 test('undefined', () => expectEnv(undefined, false));18 test('empty', () => expectEnv('', false));19 test('false', () => expectEnv('false', false));20 test('0', () => expectEnv('0', false));21 test('no', () => expectEnv('no', false));22 test('true', () => expectEnv('true', true));23 test('1', () => expectEnv('1', true));24 test('yes', () => expectEnv('yes', true));25 test('bla', () => expectEnv('bla', true));26});27describe('setDryRun', () => {28 function expectSet(flag, active) {29 const dryrun = require('./index');30 dryrun.setDryRun(flag);31 expect(dryrun.isDryRun()).toBe(active);32 expect(dryrun.shouldPerform()).toBe(!active);33 }34 test('empty', () => expectSet(undefined, true));35 test('true', () => expectSet(true, true));36 test('false', () => expectSet(false, false));37});38test('reset', () => {39 const dryrun = require('./index');40 dryrun.setDryRun(true);41 dryrun.resetDryRun();42 expect(dryrun.isDryRun()).toBe(false);43 expect(dryrun.shouldPerform()).toBe(true);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.start({3}, function (error) {4 if (error) {5 console.log(error);6 } else {7 console.log("Mountebank started");8 mb.dryRun({9 }, function (error) {10 if (error) {11 console.log(error);12 } else {13 console.log("Mountebank dry run");14 }15 });16 }17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var imposterPort = 3000;4var imposterProtocol = 'http';5var imposterStub = {6 {7 equals: {8 }9 }10 {11 is: {12 }13 }14};15var imposter = {16};17mb.create({port: port, ipWhitelist: ['*']}, function (error, mbServer) {18 mbServer.dryRun(imposter, function (error, result) {19 console.log(result);20 });21});22{ errors: [],23 imposters: [ { port: 3000, protocol: 'http', stubs: [Object] } ] }24var mb = require('mountebank');25var port = 2525;26var imposterPort = 3000;27var imposterProtocol = 'http';28var imposterStub = {29 {30 equals: {31 }32 }33 {34 is: {35 }36 }37};38var imposter = {39};40mb.create({port: port, ipWhitelist: ['*']}, function (error, mbServer) {41 mbServer.create(imposter, function (error, result) {42 console.log(result);43 });44});45{ errors: [],46 imposters: [ { port: 3000, protocol: 'http', stubs: [Object] } ] }47var mb = require('mountebank');48var port = 2525;49var imposterPort = 3000;50var imposterProtocol = 'http';

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var mbServer = mb.create();3var stub = {4 {5 is: {6 headers: {7 },8 body: JSON.stringify({result: 'success'})9 }10 }11};12var predicate = {13 equals: {14 }15};16var imposter = {17 {18 {19 is: {20 headers: {21 },22 body: JSON.stringify({result: 'success'})23 }24 }25 }26};27mbServer.createImposter(4545, imposter, {dryRun: true}, function (error, imposter) {28 if (error) {29 console.error('Error creating imposter', error);30 }31 else {32 console.log('Imposter successfully created', imposter);33 }34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var assert = require('assert');3var fs = require('fs');4var data = fs.readFileSync('imposters.json');5var imposters = JSON.parse(data);6mb.dryRun({ imposters: imposters }, function (error, result) {7 assert.equal(error, null);8 assert.equal(result, 'valid');9});10 throw new assert.AssertionError({

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful