Best JavaScript code snippet using devicefarmer-stf
index.ts
Source:index.ts
...565 },566 },567 ["command", "--help"]568 );569 restoreLogs();570 expect(getLogs()).toMatchSnapshot();571 });572 it("Shows subcommands in scope help.", async () => {573 const [getLogs, restoreLogs] = captureLogs();574 await rapider.run(575 {576 scopes: {577 command: {578 name: "Command",579 description: "Lorem ipsum delorum.",580 scopes: {581 foo: {},582 bar: {},583 },584 },585 },586 },587 ["command", "--help"]588 );589 restoreLogs();590 expect(getLogs()).toMatchSnapshot();591 });592 it("Shows named flags in help.", async () => {593 const [getLogs, restoreLogs] = captureLogs();594 await rapider.run(595 {596 scopes: {597 command: {598 name: "Command",599 description: "Lorem ipsum delorum.",600 flags: {601 named: [602 { key: "foo", type: rapider.flags.types.string() },603 {604 key: "bar",605 aliases: ["b"],606 type: rapider.flags.types.float(),607 description: "hello",608 },609 ],610 },611 },612 },613 },614 ["command", "--help"]615 );616 restoreLogs();617 expect(getLogs()).toMatchSnapshot();618 });619 it("Shows positional flags in help.", async () => {620 const [getLogs, restoreLogs] = captureLogs();621 await rapider.run(622 {623 scopes: {624 command: {625 name: "Command",626 description: "Lorem ipsum delorum.",627 flags: {628 positional: [629 { key: "foo", type: rapider.flags.types.string() },630 {631 key: "bar",632 type: rapider.flags.types.float(),633 description: "hello",634 },635 ],636 },637 },638 },639 },640 ["command", "--help"]641 );642 restoreLogs();643 expect(getLogs()).toMatchSnapshot();644 });645});646describe("Flag Rules", () => {647 describe("One Of", () => {648 it("Shows no error if string argument one of approved items.", async () => {649 const spy = jest.fn();650 await rapider.run(651 {652 scopes: {653 command: {654 name: "Command",655 description: "Lorem ipsum delorum.",656 flags: {657 named: [658 {659 key: "foo",660 type: rapider.flags.types.string(),661 rules: [662 rapider.flags.rules.oneOf(() => ["apple", "orange"]),663 rapider.flags.rules.required(),664 ],665 },666 ],667 },668 handler: spy,669 },670 },671 },672 ["command", "--foo", "apple"]673 );674 expect(spy).toHaveBeenCalledWith(675 expect.objectContaining({676 foo: "apple",677 })678 );679 });680 it("Shows error if string argument not one of approved items.", async () => {681 const spy = jest.fn();682 await expect(683 rapider.run(684 {685 scopes: {686 command: {687 name: "Command",688 description: "Lorem ipsum delorum.",689 flags: {690 named: [691 {692 key: "foo",693 type: rapider.flags.types.string(),694 rules: [695 rapider.flags.rules.oneOf(() => ["apple", "orange"]),696 rapider.flags.rules.required(),697 ],698 },699 ],700 },701 handler: spy,702 },703 },704 },705 ["command", "--foo", "banana"]706 )707 ).rejects.toMatchObject({ message: expect.stringMatching("foo") });708 expect(spy).not.toHaveBeenCalled();709 });710 });711 describe("Length", () => {712 it("Shows no error if string argument is of required length.", async () => {713 const spy = jest.fn();714 await rapider.run(715 {716 scopes: {717 command: {718 name: "Command",719 description: "Lorem ipsum delorum.",720 flags: {721 named: [722 {723 key: "foo",724 type: rapider.flags.types.string(),725 rules: [726 rapider.flags.rules.length(() => 5),727 rapider.flags.rules.required(),728 ],729 },730 ],731 },732 handler: spy,733 },734 },735 },736 ["command", "--foo", "12345"]737 );738 expect(spy).toHaveBeenCalledWith({ foo: "12345" });739 });740 it("Shows error if string argument not of required length.", async () => {741 const spy = jest.fn();742 await expect(743 rapider.run(744 {745 scopes: {746 command: {747 name: "Command",748 description: "Lorem ipsum delorum.",749 flags: {750 named: [751 {752 key: "foo",753 type: rapider.flags.types.string(),754 rules: [755 rapider.flags.rules.length(() => 5),756 rapider.flags.rules.required(),757 ],758 },759 ],760 },761 handler: spy,762 },763 },764 },765 ["command", "--foo", "banana"]766 )767 ).rejects.toMatchObject({ message: expect.stringMatching("foo") });768 expect(spy).not.toHaveBeenCalled();769 });770 });771 describe("Dependencies", () => {772 it("Shows error if dependent rule is not satisfied.", async () => {773 const spy = jest.fn();774 await expect(775 rapider.run(776 {777 scopes: {778 command: {779 name: "Command",780 description: "Lorem ipsum delorum.",781 flags: {782 named: [783 {784 key: "from",785 type: rapider.flags.types.date(),786 rules: [rapider.flags.rules.required()],787 },788 {789 key: "to",790 type: rapider.flags.types.date(),791 rules: [792 rapider.flags.rules.required(),793 rapider.flags.rules.greaterThan((flags) => flags.from),794 ],795 },796 ],797 },798 handler: spy,799 },800 },801 },802 ["command", "--from", "2021-8-1", "--to", "2021-7-1"]803 )804 ).rejects.toMatchObject({ message: expect.stringMatching("to") });805 expect(spy).not.toHaveBeenCalled();806 });807 it("Shows no error if dependent rule is satisfied.", async () => {808 const spy = jest.fn();809 await rapider.run(810 {811 scopes: {812 command: {813 name: "Command",814 description: "Lorem ipsum delorum.",815 flags: {816 named: [817 {818 key: "from",819 type: rapider.flags.types.date(),820 rules: [rapider.flags.rules.required()],821 },822 {823 key: "to",824 type: rapider.flags.types.date(),825 rules: [826 rapider.flags.rules.required(),827 rapider.flags.rules.greaterThan((flags) => flags.from),828 ],829 },830 ],831 },832 handler: spy,833 },834 },835 },836 ["command", "--from", "2021-8-1", "--to", "2021-9-1"]837 );838 expect(spy).toHaveBeenCalled();839 });840 });841 describe("Files", () => {842 it("can check if file exists.", async () => {843 const spy = jest.fn();844 await rapider.run(845 {846 scopes: {847 command: {848 flags: {849 named: [850 {851 key: "foo",852 type: rapider.flags.types.path(),853 rules: [rapider.flags.rules.pathExists({})],854 },855 ],856 },857 handler: spy,858 },859 },860 },861 ["command", "--foo", "/tmp"]862 );863 expect(spy).toHaveBeenCalledWith({ foo: "/tmp" });864 });865 it("can throw error if file doesn't exist.", async () => {866 const spy = jest.fn();867 await expect(868 rapider.run(869 {870 scopes: {871 command: {872 flags: {873 named: [874 {875 key: "foo",876 type: rapider.flags.types.path(),877 rules: [rapider.flags.rules.pathExists({})],878 },879 ],880 },881 handler: spy,882 },883 },884 },885 ["command", "--foo", "/tmpp"]886 )887 ).rejects.toMatchObject({ message: expect.stringContaining("foo") });888 });889 it("can check if file parent exists, e.g for output files.", async () => {890 const spy = jest.fn();891 await rapider.run(892 {893 scopes: {894 command: {895 flags: {896 named: [897 {898 key: "foo",899 type: rapider.flags.types.path(),900 rules: [rapider.flags.rules.pathExists({ parent: true })],901 },902 ],903 },904 handler: spy,905 },906 },907 },908 ["command", "--foo", "src/fakefile.js"]909 );910 expect(spy).toHaveBeenCalledWith({911 foo: path.join(process.cwd(), "src/fakefile.js"),912 });913 });914 });915 describe("Allowed", () => {916 it("Does not allow flag if allowed is false.", async () => {917 const spy = jest.fn();918 await expect(919 rapider.run(920 {921 scopes: {922 command: {923 flags: {924 named: [925 {926 key: "foo",927 type: rapider.flags.types.string(),928 rules: [rapider.flags.rules.allowed(() => false)],929 },930 ],931 },932 handler: spy,933 },934 },935 },936 ["command", "--foo", "apple"]937 )938 ).rejects.toMatchObject({ message: expect.stringContaining("foo") });939 });940 it("allows flag if allowed is true.", async () => {941 const spy = jest.fn();942 await rapider.run(943 {944 scopes: {945 command: {946 flags: {947 named: [948 {949 key: "foo",950 type: rapider.flags.types.string(),951 rules: [rapider.flags.rules.required(() => true)],952 },953 ],954 },955 handler: spy,956 },957 },958 },959 ["command", "--foo", "true"]960 );961 });962 });963 describe("Required", () => {964 it("enforces required if not specified", async () => {965 const spy = jest.fn();966 await expect(967 rapider.run(968 {969 scopes: {970 command: {971 flags: {972 named: [973 {974 key: "foo",975 type: rapider.flags.types.string(),976 rules: [rapider.flags.rules.required()],977 },978 ],979 },980 handler: spy,981 },982 },983 },984 ["command"]985 )986 ).rejects.toMatchObject({ message: expect.stringContaining("foo") });987 });988 it("does not enforce required if false", async () => {989 const spy = jest.fn();990 await rapider.run(991 {992 scopes: {993 command: {994 flags: {995 named: [996 {997 key: "foo",998 type: rapider.flags.types.path(),999 rules: [rapider.flags.rules.required(() => false)],1000 },1001 ],1002 },1003 handler: spy,1004 },1005 },1006 },1007 ["command"]1008 );1009 });1010 it("enforces required if 'true'", async () => {1011 const spy = jest.fn();1012 await expect(1013 rapider.run(1014 {1015 scopes: {1016 command: {1017 flags: {1018 named: [1019 {1020 key: "foo",1021 type: rapider.flags.types.path(),1022 rules: [rapider.flags.rules.required()],1023 },1024 ],1025 },1026 handler: spy,1027 },1028 },1029 },1030 ["command"]1031 )1032 ).rejects.toMatchObject({ message: expect.stringContaining("foo") });1033 });1034 });1035 describe("Custom", () => {1036 it("calls custom rule checker.", async () => {1037 const spy = jest.fn();1038 const ruleSpy = jest.fn().mockImplementation((data) => true);1039 await rapider.run(1040 {1041 scopes: {1042 command: {1043 flags: {1044 named: [1045 {1046 key: "foo",1047 type: rapider.flags.types.string(),1048 rules: [rapider.flags.rules.custom(ruleSpy)],1049 },1050 ],1051 },1052 handler: spy,1053 },1054 },1055 },1056 ["command", "--foo", "apple"]1057 );1058 expect(spy).toHaveBeenCalledWith({ foo: "apple" });1059 expect(ruleSpy).toHaveBeenCalledWith(1060 "apple",1061 expect.objectContaining({ foo: "apple" })1062 );1063 });1064 });1065});1066describe("Basic Runner", () => {1067 it("Calls cli handler with no sub-commands or other args.", async () => {1068 const spy = jest.fn();1069 await rapider.run({1070 handler: spy,1071 });1072 expect(spy).toHaveBeenCalledTimes(1);1073 });1074 it("Calls correct nested cli handler.", async () => {1075 const spy = jest.fn();1076 const otherSpy = jest.fn();1077 await rapider.run(1078 {1079 scopes: {1080 parent: {1081 scopes: {1082 correct: {1083 handler: spy,1084 },1085 other: {1086 handler: otherSpy,1087 },1088 },1089 },1090 },1091 },1092 ["parent", "correct"]1093 );1094 expect(spy).toHaveBeenCalledTimes(1);1095 expect(otherSpy).not.toHaveBeenCalled();1096 });1097 it("Allows scopes to also have a default handler.", async () => {1098 const spy = jest.fn();1099 const otherSpy = jest.fn();1100 await rapider.run(1101 {1102 scopes: {1103 parent: {1104 scopes: {1105 correct: {1106 handler: otherSpy,1107 },1108 },1109 handler: spy,1110 },1111 },1112 },1113 ["parent"]1114 );1115 expect(spy).toHaveBeenCalledTimes(1);1116 expect(otherSpy).not.toHaveBeenCalled();1117 });1118 // TODO1119 // it("Does not support named arguments after positional.", async () => {});1120 it("Shows error if all elements of list flag not part of approved.", async () => {1121 const spy = jest.fn();1122 await expect(1123 rapider.run(1124 {1125 scopes: {1126 command: {1127 name: "Command",1128 description: "Lorem ipsum delorum.",1129 flags: {1130 named: [1131 {1132 key: "foo",1133 type: rapider.flags.types.list({1134 type: rapider.flags.types.string(),1135 }),1136 rules: [1137 rapider.flags.rules.allOneOf(() => ["apple", "orange"]),1138 rapider.flags.rules.required(),1139 ],1140 },1141 ],1142 },1143 handler: spy,1144 },1145 },1146 },1147 ["command", "--foo", "apple,orange,banana"]1148 )1149 ).rejects.toMatchObject({ message: expect.stringMatching("foo") });1150 expect(spy).not.toHaveBeenCalled();1151 });1152 it("Shows error if all elements of list are not unique, if specified.", async () => {1153 const spy = jest.fn();1154 await expect(1155 rapider.run(1156 {1157 scopes: {1158 command: {1159 name: "Command",1160 description: "Lorem ipsum delorum.",1161 flags: {1162 named: [1163 {1164 key: "foo",1165 type: rapider.flags.types.list({1166 type: rapider.flags.types.string(),1167 }),1168 rules: [1169 rapider.flags.rules.unique(),1170 rapider.flags.rules.required(),1171 ],1172 },1173 ],1174 },1175 handler: spy,1176 },1177 },1178 },1179 ["command", "--foo", "apple,orange,apple"]1180 )1181 ).rejects.toMatchObject({ message: expect.stringMatching("foo") });1182 expect(spy).not.toHaveBeenCalled();1183 });1184 it("Shows no error if all elements of list unique, if specified.", async () => {1185 const spy = jest.fn();1186 await rapider.run(1187 {1188 scopes: {1189 command: {1190 name: "Command",1191 description: "Lorem ipsum delorum.",1192 flags: {1193 named: [1194 {1195 key: "foo",1196 type: rapider.flags.types.list({1197 type: rapider.flags.types.string(),1198 }),1199 rules: [1200 rapider.flags.rules.unique(),1201 rapider.flags.rules.required(),1202 ],1203 },1204 ],1205 },1206 handler: spy,1207 },1208 },1209 },1210 ["command", "--foo", "apple,orange,banana"]1211 );1212 expect(spy).toHaveBeenCalledWith(1213 expect.objectContaining({1214 foo: ["apple", "orange", "banana"],1215 })1216 );1217 });1218});1219describe("UI", () => {1220 describe("Logging", () => {1221 it("Shows various logs.", () => {1222 const [getLogs, restoreLogs] = captureLogs();1223 rapider.ui.logs.LOG("a");1224 rapider.ui.logs.INFO("b");1225 rapider.ui.logs.WARN("c");1226 rapider.ui.logs.SUCCESS("d");1227 expect(getLogs()).toMatchSnapshot();1228 restoreLogs();1229 });1230 describe("Smart Logs", () => {1231 it("Can clear log.", () => {1232 const [getLogs, restoreLogs] = captureLogs();1233 const log = rapider.ui.logs.LOG("hello");1234 log.clear();1235 restoreLogs();1236 expect(getLogs()).toMatchSnapshot();1237 });1238 it("Can clear logs further back in history.", () => {1239 const [getLogs, restoreLogs] = captureLogs();1240 const log1 = rapider.ui.logs.LOG("hello1");1241 const log2 = rapider.ui.logs.LOG("hello2");1242 log1.clear();1243 restoreLogs();1244 expect(getLogs()).toMatchSnapshot();1245 });1246 it("Can delete latest log.", () => {1247 const [getLogs, restoreLogs] = captureLogs();1248 const log = rapider.ui.logs.LOG("hello");1249 log.delete();1250 restoreLogs();1251 expect(getLogs()).toMatchSnapshot();1252 });1253 it("Can delete further back log.", () => {1254 const [getLogs, restoreLogs] = captureLogs();1255 const log1 = rapider.ui.logs.LOG("hello1");1256 const log2 = rapider.ui.logs.LOG("hello2");1257 log1.delete();1258 restoreLogs();1259 expect(getLogs()).toMatchSnapshot();1260 });1261 it("Can refresh latest log.", () => {1262 const [getLogs, restoreLogs] = captureLogs();1263 const log = rapider.ui.logs.LOG("hello");1264 log.refresh("hello2");1265 restoreLogs();1266 expect(getLogs()).toMatchSnapshot();1267 });1268 it("Can refresh further back log.", () => {1269 const [getLogs, restoreLogs] = captureLogs();1270 const log1 = rapider.ui.logs.LOG("hello1");1271 const log2 = rapider.ui.logs.LOG("hello2");1272 log1.refresh("hello3");1273 restoreLogs();1274 expect(getLogs()).toMatchSnapshot();1275 });1276 });1277 describe("Indenting", () => {1278 it("Allows indenting.", () => {1279 const [getLogs, restoreLogs] = captureLogs();1280 rapider.ui.logs.indent.increase();1281 rapider.ui.logs.LOG("test");1282 rapider.ui.logs.indent.decrease();1283 restoreLogs();1284 expect(getLogs()).toMatchSnapshot();1285 });1286 it("Allows un-indenting.", () => {1287 const [getLogs, restoreLogs] = captureLogs();1288 rapider.ui.logs.indent.increase();1289 rapider.ui.logs.indent.decrease();1290 rapider.ui.logs.LOG("test");1291 restoreLogs();1292 expect(getLogs()).toMatchSnapshot();1293 });1294 it("Allows indent reset.", () => {1295 const [getLogs, restoreLogs] = captureLogs();1296 rapider.ui.logs.indent.increase();1297 rapider.ui.logs.indent.reset();1298 rapider.ui.logs.LOG("test");1299 restoreLogs();1300 expect(getLogs()).toMatchSnapshot();1301 });1302 });1303 describe("Progress", () => {1304 it("Shows progress bar with initial 0.", () => {1305 const [getLogs, restoreLogs] = captureLogs();1306 const pb = rapider.ui.logs.progressBar({});1307 const logs = getLogs();1308 expect(logs).toContainEqual(expect.stringMatching("0%"));1309 expect(getLogs()).toMatchSnapshot();1310 restoreLogs();1311 });1312 it("Shows progress bar with custom initial.", () => {1313 const [getLogs, restoreLogs] = captureLogs();1314 const pb = rapider.ui.logs.progressBar({ initial: 0.5 });1315 const logs = getLogs();1316 expect(logs).toContainEqual(expect.stringMatching("50%"));1317 expect(getLogs()).toMatchSnapshot();1318 restoreLogs();1319 });1320 it("Allows updating progress bar.", () => {1321 const [getLogs, restoreLogs] = captureLogs();1322 const pb = rapider.ui.logs.progressBar({});1323 pb.set(0.5);1324 const logs = getLogs();1325 expect(logs).toContainEqual(expect.stringMatching("50%"));1326 expect(getLogs()).toMatchSnapshot();1327 restoreLogs();1328 });1329 it("Allows updating progress bar with items.", () => {1330 const [getLogs, restoreLogs] = captureLogs();1331 const pb = rapider.ui.logs.progressBar({});1332 pb.set(0.5, ["foo", "bar"]);1333 const logs = getLogs();1334 expect(logs).toContainEqual(expect.stringMatching("50%"));1335 expect(logs).toContainEqual(expect.stringMatching("foo"));1336 expect(logs).toContainEqual(expect.stringMatching("bar"));1337 expect(getLogs()).toMatchSnapshot();1338 restoreLogs();1339 });1340 it("Allows updating progress bar with less items.", () => {1341 const [getLogs, restoreLogs] = captureLogs();1342 const pb = rapider.ui.logs.progressBar({});1343 pb.set(0.5, ["foo", "bar"]);1344 pb.set(0.5, ["foo"]);1345 const logs = getLogs();1346 expect(getLogs()).toMatchSnapshot();1347 restoreLogs();1348 });1349 it("Allows updating progress bar with more items.", () => {1350 const [getLogs, restoreLogs] = captureLogs();1351 const pb = rapider.ui.logs.progressBar({});1352 pb.set(0.5, ["foo", "bar"]);1353 pb.set(0.5, ["foo", "bar", "yo"]);1354 const logs = getLogs();1355 expect(getLogs()).toMatchSnapshot();1356 restoreLogs();1357 });1358 it("Handles negative progress.", () => {1359 const [getLogs, restoreLogs] = captureLogs();1360 const pb = rapider.ui.logs.progressBar({ initial: -0.05 });1361 const logs = getLogs();1362 expect(logs).toContainEqual(expect.stringMatching("-5%"));1363 expect(getLogs()).toMatchSnapshot();1364 restoreLogs();1365 });1366 it("Handles >1 progress.", () => {1367 const [getLogs, restoreLogs] = captureLogs();1368 const pb = rapider.ui.logs.progressBar({ initial: 1.05 });1369 const logs = getLogs();1370 expect(logs).toContainEqual(expect.stringMatching("105%"));1371 expect(getLogs()).toMatchSnapshot();1372 restoreLogs();1373 });1374 });1375 describe("Spinner", () => {1376 it("Changes over time", (done) => {1377 const [getLogs, restoreLogs] = captureLogs();1378 const s = rapider.ui.logs.spinner();1379 expect.assertions(1);1380 setTimeout(() => {1381 s.dismiss();1382 restoreLogs();1383 expect(getLogs()).toMatchSnapshot();1384 done();1385 }, 1000);1386 });1387 it("Supports labels", () => {1388 const [getLogs, restoreLogs] = captureLogs();1389 const s = rapider.ui.logs.spinner();1390 s.dismiss();1391 restoreLogs();1392 expect(getLogs()).toMatchSnapshot();1393 });1394 it("Can wrap a promise.", (done) => {1395 const dismissSpy = jest.fn();1396 const s = rapider.ui.logs.spinner().wrap(1397 new Promise((resolve) => {1398 setTimeout(resolve, 2000);1399 })1400 );1401 const originalDismiss = s.dismiss;1402 dismissSpy.mockImplementation(originalDismiss);1403 s.dismiss = dismissSpy;1404 setTimeout(() => {1405 expect(dismissSpy).toHaveBeenCalledTimes(1);1406 done();1407 }, 2500);1408 });1409 });1410 });1411 describe("Data", () => {1412 it("displays table", () => {1413 const [getLogs, restoreLogs] = captureLogs();1414 rapider.ui.data1415 .table({1416 cols: { id: "ID", name: "Animal" },1417 rows: [1418 { id: 1, name: "Pig" },1419 { id: 2, name: "Cow" },1420 { id: 3, name: "Sheep" },1421 ],1422 })1423 .print();1424 restoreLogs();1425 expect(getLogs()).toMatchSnapshot();1426 });1427 it("displays list", () => {1428 const [getLogs, restoreLogs] = captureLogs();1429 rapider.ui.data1430 .list({1431 title: "Animals",1432 items: ["Pig", "Cow", "Sheep"],1433 })1434 .print();1435 restoreLogs();1436 expect(getLogs()).toMatchSnapshot();1437 });1438 });1439});1440describe("Store", () => {1441 // TODO: use separate fir for testing.1442 const rapiderDir = path.join(os.homedir(), ".rapider");1443 afterEach(async () => {1444 if (fs.existsSync(rapiderDir)) {1445 fs.rmSync(rapiderDir, {1446 recursive: true,1447 force: true,1448 });1449 }...
operators.RestoreService.spec.js
Source:operators.RestoreService.spec.js
1'use strict';2const _ = require('lodash');3const {4 catalog,5 Service6} = require('@sf/models');7const RestoreService = require('../src/restore-operator/RestoreService');8const moment = require('moment');9const config = require('@sf/app-config');10const { CONST } = require('@sf/common-utils');11const { backupStore } = require('@sf/iaas');12describe('operators', function () {13 describe('RestoreService', function () {14 function isoDate(time) {15 return new Date(time).toISOString().replace(/\.\d*/, '').replace(/:/g, '-');16 }17 let plan;18 const plan_id = 'bc158c9a-7934-401e-94ab-057082a5073f';19 const restoreGuid = '2ed8d561-9eb5-11e8-a55f-784f43900dff';20 const deployment_name = 'service-fabrik-0021-b4719e7c-e8d3-4f7f-c515-769ad1c3ebfa';21 const space_guid = 'e7c0a437-7585-4d75-addf-aa4d45b49f3a';22 const service_id = '24731fb8-7b84-4f57-914f-c3d55d793dd4';23 const instance_id = 'b4719e7c-e8d3-4f7f-c515-769ad1c3ebfa';24 const backup_guid = '071acb05-66a3-471b-af3c-8bbf1e4180be';25 const time = Date.now();26 const agent_ip = '10.244.10.160';27 const username = 'fakeUsername';28 const started_at = isoDate(time);29 const restorePrefix = `${space_guid}/restore/${service_id}.${instance_id}`;30 const container = backupStore.containerName;31 const restoreFilename = `${restorePrefix}.json`;32 const restorePathname = `/${container}/${restoreFilename}`;33 const restoreMetadata = {34 plan_id: plan_id,35 state: 'succeeded',36 type: 'online',37 secret: 'fakeSecret',38 started_at: started_at,39 trigger: 'online',40 restore_dates: {41 succeeded: [42 moment(time).subtract(2, 'days').toDate().toISOString(),43 moment(time).subtract(40, 'days').toDate().toISOString()44 ]45 }46 };47 const get_restore_opts = {48 type: 'update',49 deployment: 'service-fabrik-0021-b4719e7c-e8d3-4f7f-c515-769ad1c3ebfa',50 context: {51 platform: 'cloudfoundry',52 organization_guid: 'c84c8e58-eedc-4706-91fb-e8d97b333481',53 space_guid: 'e7c0a437-7585-4d75-addf-aa4d45b49f3a'54 },55 agent_ip: agent_ip,56 instance_guid: 'b4719e7c-e8d3-4f7f-c515-769ad1c3ebfa',57 restore_guid: restoreGuid58 };59 const restore_options = {60 restore_guid: restoreGuid,61 plan_id: 'bc158c9a-7934-401e-94ab-057082a5073f',62 service_id: '24731fb8-7b84-4f57-914f-c3d55d793dd4',63 context: {64 platform: 'cloudfoundry',65 organization_guid: 'c84c8e58-eedc-4706-91fb-e8d97b333481',66 space_guid: 'e7c0a437-7585-4d75-addf-aa4d45b49f3a'67 },68 instance_guid: 'b4719e7c-e8d3-4f7f-c515-769ad1c3ebfa',69 deployment: deployment_name,70 arguments: {71 backup_guid: backup_guid,72 backup: {73 type: 'online',74 secret: 'fakeSecret'75 }76 },77 username: username78 };79 const dummyDeploymentResource = {80 metadata: {81 annotations: {82 labels: 'dummy'83 }84 }85 };86 beforeEach(function () {87 plan = catalog.getPlan(plan_id);88 mocks.reset();89 });90 describe('#abortLastRestore', function () {91 it('should abort restore if state is processing', function () {92 mocks.cloudProvider.download(restorePathname, _93 .chain(restoreMetadata)94 .omit('state')95 .set('state', 'processing')96 .set('agent_ip', mocks.agent.ip)97 .value()98 );99 // mocks.cloudProvider.auth();100 // mocks.agent.getInfo();101 mocks.agent.abortRestore();102 mocks.apiServerEventMesh.nockPatchResourceRegex(CONST.APISERVER.RESOURCE_GROUPS.BACKUP, CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {103 status: {104 state: 'aborting'105 }106 }, 1, body => {107 expect(body.status.state).to.eql('aborting');108 expect(body.status.response).to.be.an('undefined');109 return true;110 });111 return RestoreService.createService(plan)112 .then(rs => rs.abortLastRestore(restore_options))113 .then(() => mocks.verify());114 });115 it('should return state if state is not processing', function () {116 mocks.cloudProvider.download(restorePathname, _117 .chain(restoreMetadata)118 .omit('state')119 .set('state', 'succeeded')120 .value()121 );122 // mocks.cloudProvider.auth();123 return RestoreService.createService(plan)124 .then(rs => rs.abortLastRestore(restore_options))125 .then(() => mocks.verify());126 });127 });128 describe('#startRestore', function () {129 it('should start restore', function () {130 mocks.director.getDeploymentVms(deployment_name);131 mocks.apiServerEventMesh.nockGetResource(CONST.APISERVER.RESOURCE_GROUPS.DEPLOYMENT, CONST.APISERVER.RESOURCE_TYPES.DIRECTOR, instance_id, dummyDeploymentResource);132 mocks.apiServerEventMesh.nockPatchResource(CONST.APISERVER.RESOURCE_GROUPS.DEPLOYMENT, CONST.APISERVER.RESOURCE_TYPES.DIRECTOR, instance_id);133 mocks.director.getDeploymentInstances(deployment_name);134 mocks.director.getDeployments();135 mocks.agent.getInfo();136 // mocks.agent.getInfo();137 // mocks.cloudProvider.auth();138 mocks.agent.startRestore();139 mocks.cloudProvider.upload(restorePathname, body => {140 expect(body.state).to.equal(CONST.RESTORE_OPERATION.PROCESSING);141 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line142 return true;143 });144 mocks.cloudProvider.headObject(restorePathname);145 mocks.apiServerEventMesh.nockPatchResourceRegex(CONST.APISERVER.RESOURCE_GROUPS.BACKUP, CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {}, 1, body => {146 const responseObj = JSON.parse(body.status.response);147 expect(responseObj.service_id).to.eql(service_id);148 expect(responseObj.plan_id).to.eql(plan_id);149 expect(responseObj.instance_guid).to.eql(instance_id);150 expect(responseObj.username).to.eql(username);151 expect(responseObj.operation).to.eql(CONST.OPERATION_TYPE.RESTORE);152 expect(responseObj.backup_guid).to.eql(backup_guid);153 expect(responseObj.state).to.eql(CONST.RESTORE_OPERATION.PROCESSING);154 expect(responseObj.agent_ip).to.eql(agent_ip);155 // expect(responseObj.started_at).to.eql(started_at);156 expect(responseObj.finished_at).to.eql(null);157 expect(responseObj.tenant_id).to.eql(space_guid);158 // expect(responseObj.restore_dates).to.eql('fillin');159 // expect(responseObj.stage).to.eql('fillin');160 return true;161 });162 return RestoreService.createService(plan)163 .then(rs => rs.startRestore(restore_options))164 .then(() => mocks.verify());165 });166 });167 describe('#getLastRestore', function () {168 it('last opeation should download the restore logs and update the metadata', function () {169 const state = 'succeeded';170 const restoreState = {171 state: state,172 stage: 'Finished',173 updated_at: new Date(Date.now())174 };175 mocks.cloudProvider.download(restorePathname, {176 state: 'processing',177 'agent_ip': mocks.agent.ip178 });179 mocks.agent.lastRestoreOperation(restoreState);180 return RestoreService.createService(plan)181 .then(rs => rs.getLastRestore(space_guid, instance_id))182 .then(() => mocks.verify());183 });184 });185 describe('#getRestoreOperationState', function () {186 it('#getRestoreOperationState Should get restore state - processing', function () {187 const restoreState = {188 state: 'processing',189 stage: 'Restoring ...',190 updated_at: started_at191 };192 mocks.agent.lastRestoreOperation(restoreState);193 return RestoreService.createService(plan)194 .then(rs => rs.getRestoreOperationState(get_restore_opts))195 .then(() => mocks.verify());196 });197 it('should download the restore logs and update the metadata', function () {198 const state = 'succeeded';199 const restoreState = {200 state: state,201 stage: 'Finished',202 updated_at: new Date(Date.now())203 };204 const restoreLogs = [{205 time: '2015-11-18T11:28:40+00:00',206 level: 'info',207 msg: 'Downloading tarball ...'208 }, {209 time: '2015-11-18T11:28:42+00:00',210 level: 'info',211 msg: 'Extracting tarball ...'212 }];213 const restoreLogsStream = _214 .chain(restoreLogs)215 .map(JSON.stringify)216 .join('\n')217 .value();218 // mocks.agent.getInfo();219 // mocks.cloudProvider.auth();220 // mocks.uaa.getAccessToken();221 mocks.cloudProvider.download(restorePathname, {}, 2);222 mocks.agent.lastRestoreOperation(restoreState);223 mocks.agent.getRestoreLogs(restoreLogsStream);224 mocks.cloudProvider.upload(restorePathname, body => {225 expect(body.logs).to.eql(restoreLogs);226 expect(body.state).to.equal(state);227 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line228 return true;229 });230 mocks.cloudProvider.headObject(restorePathname);231 mocks.serviceFabrikClient.scheduleBackup(instance_id, function (body) {232 return body.type === CONST.BACKUP.TYPE.ONLINE;233 });234 mocks.apiServerEventMesh.nockPatchResourceRegex(235 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,236 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {});237 mocks.apiServerEventMesh.nockGetResourceRegex(238 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,239 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {240 status: {241 state: CONST.OPERATION.IN_PROGRESS,242 response: '{"guid": "some_guid"}'243 }244 });245 return RestoreService.createService(plan)246 .then(rs => rs.getRestoreOperationState(get_restore_opts))247 .then(() => mocks.verify());248 });249 it('should download the restore logs and update the metadata - shoudn\'t schedule backup (duplicate check) ', function () {250 const state = 'succeeded';251 const restoreState = {252 state: state,253 stage: 'Finished',254 updated_at: '2015-11-18T11:28:44Z'255 };256 const restoreLogs = [{257 time: '2015-11-18T11:28:40+00:00',258 level: 'info',259 msg: 'Downloading tarball ...'260 }, {261 time: '2015-11-18T11:28:42+00:00',262 level: 'info',263 msg: 'Extracting tarball ...'264 },265 {266 time: '2015-11-18T11:28:44+00:00',267 level: 'info',268 msg: 'Restore finished'269 }270 ];271 const restoreLogsStream = _272 .chain(restoreLogs)273 .map(JSON.stringify)274 .join('\n')275 .value();276 mocks.cloudProvider.download(restorePathname, _.assign(_.cloneDeep(restoreMetadata), {277 restore_dates: {278 succeeded: ['2015-11-18T11:28:44.000Z']279 }280 }), 2);281 // mocks.agent.getInfo();282 // mocks.cloudProvider.auth();283 // mocks.uaa.getAccessToken();284 mocks.agent.lastRestoreOperation(restoreState);285 mocks.agent.getRestoreLogs(restoreLogsStream);286 mocks.cloudProvider.upload(restorePathname, body => {287 expect(body.logs).to.eql(restoreLogs);288 expect(body.state).to.equal(state);289 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line290 return true;291 });292 mocks.cloudProvider.headObject(restorePathname);293 mocks.apiServerEventMesh.nockPatchResourceRegex(294 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,295 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {});296 mocks.apiServerEventMesh.nockGetResourceRegex(297 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,298 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {299 status: {300 state: CONST.OPERATION.IN_PROGRESS,301 response: '{"guid": "some_guid"}'302 }303 });304 return RestoreService.createService(plan)305 .then(rs => rs.getRestoreOperationState(get_restore_opts))306 .then(() => mocks.verify());307 });308 it('should download the restore logs and update the metadata but don\'t schedule backup (failed restore)', function () {309 const state = 'failed';310 const restoreState = {311 state: state,312 stage: 'Finished',313 updated_at: new Date(Date.now())314 };315 const restoreLogs = [{316 time: '2015-11-18T11:28:40+00:00',317 level: 'info',318 msg: 'Downloading tarball ...'319 }, {320 time: '2015-11-18T11:28:42+00:00',321 level: 'info',322 msg: 'Extracting tarball error ...'323 }];324 const restoreLogsStream = _325 .chain(restoreLogs)326 .map(JSON.stringify)327 .join('\n')328 .value();329 mocks.cloudProvider.download(restorePathname, {}, 2);330 mocks.agent.lastRestoreOperation(restoreState);331 mocks.agent.getRestoreLogs(restoreLogsStream);332 mocks.cloudProvider.upload(restorePathname, body => {333 expect(body.logs).to.eql(restoreLogs);334 expect(body.state).to.equal(state);335 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line336 return true;337 });338 mocks.cloudProvider.headObject(restorePathname);339 mocks.apiServerEventMesh.nockPatchResourceRegex(340 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,341 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {});342 mocks.apiServerEventMesh.nockGetResourceRegex(343 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,344 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {345 status: {346 state: CONST.OPERATION.IN_PROGRESS,347 response: '{"guid": "some_guid"}'348 }349 });350 return RestoreService.createService(plan)351 .then(rs => rs.getRestoreOperationState(get_restore_opts))352 .then(() => mocks.verify());353 });354 describe('#non-pitr-services:', function () {355 const indexOfService = _.findIndex(config.services, service => service.pitr === true);356 const non_pitr_plan_id = 'b715f834-2048-11e7-a560-080027afc1e6';357 const non_pitr_service_id = '19f17a7a-5247-4ee2-94b5-03eac6756388';358 const nonPitrRestorePrefix = `${space_guid}/restore/${non_pitr_service_id}.${instance_id}`;359 const nonPitrRestoreFilename = `${nonPitrRestorePrefix}.json`;360 const nonPitrRestorePathname = `/${container}/${nonPitrRestoreFilename}`;361 let getServiceStub;362 before(function () {363 config.services[indexOfService].pitr = false;364 getServiceStub = sinon.stub(catalog, 'getService');365 getServiceStub.withArgs(config.services[indexOfService].id).returns(new Service(config.services[indexOfService]));366 });367 after(function () {368 config.services[indexOfService].pitr = true;369 });370 this.afterEach(function () {371 getServiceStub.restore();372 });373 it('should download the restore logs and update the metadata - and shouldn\'t schedule backup - Non PITR service', function () {374 const state = 'succeeded';375 const restoreState = {376 state: state,377 stage: 'Finished',378 updated_at: new Date(Date.now())379 };380 const restoreLogs = [{381 time: '2015-11-18T11:28:40+00:00',382 level: 'info',383 msg: 'Downloading tarball ...'384 }, {385 time: '2015-11-18T11:28:42+00:00',386 level: 'info',387 msg: 'Extracting tarball ...'388 }];389 const restoreLogsStream = _390 .chain(restoreLogs)391 .map(JSON.stringify)392 .join('\n')393 .value();394 // mocks.cloudProvider.auth();395 // mocks.agent.getInfo();396 mocks.cloudProvider.download(nonPitrRestorePathname, {}, 2);397 mocks.agent.lastRestoreOperation(restoreState);398 mocks.agent.getRestoreLogs(restoreLogsStream);399 mocks.cloudProvider.upload(nonPitrRestorePathname, body => {400 expect(body.logs).to.eql(restoreLogs);401 expect(body.state).to.equal(state);402 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line403 return true;404 });405 mocks.cloudProvider.headObject(nonPitrRestorePathname);406 let non_pitr_plan = catalog.getPlan(non_pitr_plan_id);407 mocks.apiServerEventMesh.nockPatchResourceRegex(408 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,409 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {});410 mocks.apiServerEventMesh.nockGetResourceRegex(411 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,412 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {413 status: {414 state: CONST.OPERATION.IN_PROGRESS,415 response: '{"guid": "some_guid"}'416 }417 });418 return RestoreService.createService(non_pitr_plan)419 .then(rs => rs.getRestoreOperationState(get_restore_opts))420 .then(res => {421 expect(res.state).to.equal(state);422 expect(res).to.have.property('stage');423 mocks.verify();424 })425 .then(() => mocks.verify());426 });427 });428 it('#getRestoreOperationState Should get restore state - succeeded', function () {429 const updated_at = new Date(Date.now());430 const restoreState = {431 state: 'succeeded',432 stage: 'Restoring ...',433 updated_at: updated_at434 };435 const restoreLogs = [{436 time: '2015-11-18T11:28:40+00:00',437 level: 'info',438 msg: 'Downloading tarball ...'439 }, {440 time: '2015-11-18T11:28:42+00:00',441 level: 'info',442 msg: 'Extracting tarball ...'443 }];444 const restoreLogsStream = _445 .chain(restoreLogs)446 .map(JSON.stringify)447 .join('\n')448 .value();449 // mocks.agent.getInfo();450 mocks.agent.lastRestoreOperation(restoreState);451 // mocks.cloudProvider.auth();452 // mocks.uaa.getAccessToken();453 mocks.agent.getRestoreLogs(restoreLogsStream);454 mocks.cloudProvider.download(restorePathname, {}, 2);455 mocks.cloudProvider.upload(restorePathname, body => {456 expect(body.logs).to.eql(restoreLogs);457 expect(body.state).to.equal(CONST.OPERATION.SUCCEEDED);458 expect(body.finished_at).to.not.be.undefined; // jshint ignore:line459 return true;460 });461 mocks.cloudProvider.headObject(restorePathname);462 mocks.serviceFabrikClient.scheduleBackup(instance_id, function (body) {463 return body.type === CONST.BACKUP.TYPE.ONLINE;464 });465 mocks.apiServerEventMesh.nockPatchResourceRegex(466 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,467 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {});468 mocks.apiServerEventMesh.nockGetResourceRegex(469 CONST.APISERVER.RESOURCE_GROUPS.BACKUP,470 CONST.APISERVER.RESOURCE_TYPES.DEFAULT_RESTORE, {471 status: {472 state: CONST.OPERATION.IN_PROGRESS,473 response: '{"guid": "some_guid"}'474 }475 });476 return RestoreService.createService(plan)477 .then(rs => rs.getRestoreOperationState(get_restore_opts))478 .then(() => mocks.verify());479 });480 });481 });...
test-runner.js
Source:test-runner.js
...70 if (failed) {71 failed.put(`ðâ ${failed.description}`)72 log(`\nðµ ${failed.description} (...and ${rest.length} more)`)73 log(failed.result)74 restoreLogs()75 process.exit(1)76 }77 }78 log('\n𥳠All passed ! â
â
â
')79 restoreLogs()80}81if (import.meta.url.endsWith(process.argv[1])) {82 restoreLogs()83 const files = await getFiles()84 for (const [n, [file, tests]] of files.entries()) {85 console.time(`${n + 1}/${files.length} - ${file}`)86 for (const { description, it, is } of tests) {87 console.time(description)88 const result = await compare(it, is)89 if (result instanceof Error) {90 console.timeEnd(description)91 console.error(result)92 process.exit(1)93 }94 }95 console.timeEnd(`${n + 1}/${files.length} - ${file}`)96 }...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var device = new devicefarmer.Device();3device.restoreLogs();4var devicefarmer = require('devicefarmer-stf');5var device = new devicefarmer.Device();6device.restoreLogs();7var devicefarmer = require('devicefarmer-stf');8var device = new devicefarmer.Device();9device.restoreLogs();10var devicefarmer = require('devicefarmer-stf');11var device = new devicefarmer.Device();12device.restoreLogs();13var devicefarmer = require('devicefarmer-stf');14var device = new devicefarmer.Device();15device.restoreLogs();16var devicefarmer = require('devicefarmer-stf');17var device = new devicefarmer.Device();18device.restoreLogs();19var devicefarmer = require('devicefarmer-stf');20var device = new devicefarmer.Device();21device.restoreLogs();22var devicefarmer = require('devicefarmer-stf');23var device = new devicefarmer.Device();24device.restoreLogs();25var devicefarmer = require('devicefarmer-stf');26var device = new devicefarmer.Device();27device.restoreLogs();28var devicefarmer = require('devicefarmer-stf');29var device = new devicefarmer.Device();30device.restoreLogs();31var devicefarmer = require('devicefarmer-stf');32var device = new devicefarmer.Device();33device.restoreLogs();
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = new stf.Device();3device.restoreLogs();4var stf = require('devicefarmer-stf');5var device = new stf.Device();6device.getDeviceLogs();7var stf = require('devicefarmer-stf');8var device = new stf.Device();9device.getDeviceLogs();10var stf = require('devicefarmer-stf');11var device = new stf.Device();12device.getDeviceLogs();13var stf = require('devicefarmer-stf');14var device = new stf.Device();15device.getDeviceLogs();16var stf = require('devicefarmer-stf');17var device = new stf.Device();18device.getDeviceLogs();19var stf = require('devicefarmer-stf');20var device = new stf.Device();21device.getDeviceLogs();22var stf = require('devicefarmer-stf');23var device = new stf.Device();24device.getDeviceLogs();
Using AI Code Generation
1const { DeviceFarmClient } = require('devicefarmer-stf-client');2const client = new DeviceFarmClient();3client.restoreLogs('arn:aws:devicefarm:us-west-2:123456789012:device:ABCDEF', 'arn:aws:devicefarm:us-west-2:123456789012:run:GHIJKL', 'arn:aws:devicefarm:us-west-2:123456789012:job:MNOPQR', 'arn:aws:devicefarm:us-west-2:123456789012:upload:STUVWX')4.then((data) => {5 console.log(data);6})7.catch((err) => {8 console.log(err);9});10const { DeviceFarmClient } = require('devicefarmer-stf-client');11const client = new DeviceFarmClient();12client.getLogs('arn:aws:devicefarm:us-west-2:123456789012:device:ABCDEF', 'arn:aws:devicefarm:us-west-2:123456789012:run:GHIJKL', 'arn:aws:devicefarm:us-west-2:123456789012:job:MNOPQR', 'arn:aws:devicefarm:us-west-2:123456789012:upload:STUVWX')13.then((data) => {14 console.log(data);15})16.catch((err) => {17 console.log(err);18});19const { DeviceFarmClient } = require('devicefarmer-stf-client');20const client = new DeviceFarmClient();21client.getDevice('arn:aws:devicefarm:us-west-2:123456789012:device:ABCDEF')22.then((data) => {23 console.log(data);24})25.catch((err) => {26 console.log(err);27});28const { DeviceFarmClient } = require('devicefarmer-stf-client');29const client = new DeviceFarmClient();30client.getDeviceInstance('arn:aws:devicefarm:us-west-2:123456789012:device:ABCDEF')31.then((data) => {32 console.log(data);33})34.catch((
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = new stf.Device();3device.restoreLogs('deviceid', function (err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var stf = require('devicefarmer-stf');11var device = new stf.Device();12device.getLogs('deviceid', function (err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var stf = require('devicefarmer-stf');20var device = new stf.Device();21device.getLog('deviceid', function (err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var stf = require('devicefarmer-stf');29var device = new stf.Device();30device.getLog('deviceid', function (err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var stf = require('devicefarmer-stf');38var device = new stf.Device();39device.getLog('deviceid', function (err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var stf = require('devicefarmer-stf');47var device = new stf.Device();48device.getLog('deviceid', function (err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var stf = require('devicefarmer-stf');56var device = new stf.Device();57device.getLog('deviceid', function (err, data) {58 if (err) {
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4client.restoreLogs('device_id', function (err, data) {5 console.log('err: ' + err);6 console.log('data: ' + data);7});8var devicefarmer = require('devicefarmer-stf-client');9var client = devicefarmer.createClient({10});11client.clearLogs('device_id', function (err, data) {12 console.log('err: ' + err);13 console.log('data: ' + data);14});15var devicefarmer = require('devicefarmer-stf-client');16var client = devicefarmer.createClient({17});18client.getLogs('device_id', function (err, data) {19 console.log('err: ' + err);20 console.log('data: ' + data);21});22var devicefarmer = require('devicefarmer-stf-client');23var client = devicefarmer.createClient({24});25client.getLogs('device_id', function (err, data) {26 console.log('err: ' + err);27 console.log('data: ' + data);28});29var devicefarmer = require('devicefarmer-stf-client');30var client = devicefarmer.createClient({31});32client.getLogs('device_id', function (err, data) {33 console.log('err: ' + err);34 console.log('data: ' + data);35});36var devicefarmer = require('devicefarmer-stf-client');37var client = devicefarmer.createClient({
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4client.getDevice('deviceid', function (err, device) {5 device.restoreLogs(function (err, data) {6 console.log(data);7 });8});9var devicefarmer = require('devicefarmer-stf-client');10var client = devicefarmer.createClient({11});12client.getDevice('deviceid', function (err, device) {13 device.getLogs(function (err, data) {14 console.log(data);15 });16});17var devicefarmer = require('devicefarmer-stf-client');18var client = devicefarmer.createClient({19});20client.getDevice('deviceid', function (err, device) {21 device.getLogcat(function (err, data) {22 console.log(data);23 });24});25var devicefarmer = require('devicefarmer-stf-client');26var client = devicefarmer.createClient({27});28client.getDevice('deviceid', function (err, device) {29 device.getScreenshot(function (err, data) {30 console.log(data);31 });32});33var devicefarmer = require('devicefarmer-stf-client');34var client = devicefarmer.createClient({35});36client.getDevice('deviceid', function (err, device) {37 device.getVideo(function (err, data) {38 console.log(data);39 });40});41var devicefarmer = require('devicefarmer-stf-client');42var client = devicefarmer.createClient({43});44client.getDevice('
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2client.restoreLogs('device-id', 'path-to-logs-file', function(err, data) {3 if (err) {4 console.log(err);5 return;6 }7 console.log(data);8});9var devicefarmer = require('devicefarmer-stf');10client.clearLogs('device-id', function(err, data) {11 if (err) {12 console.log(err);13 return;14 }15 console.log(data);16});17var devicefarmer = require('devicefarmer-stf');18client.getLogcat('device-id', function(err, data) {19 if (err) {20 console.log(err);21 return;22 }23 console.log(data);24});25var devicefarmer = require('devicefarmer-stf');26client.getLogcat('device-id', function(err, data) {27 if (err) {28 console.log(err);29 return;30 }31 console.log(data);32});33var devicefarmer = require('devicefarmer-stf');34client.getLogcat('device-id', function(err, data) {35 if (err) {36 console.log(err);37 return;38 }39 console.log(data);40});41var devicefarmer = require('devicefarmer-stf');42client.getLogcat('device-id', function(err, data) {43 if (err) {44 console.log(err);45 return;46 }47 console.log(data);48});
Using AI Code Generation
1var device = require('devicefarmer-stf-device');2var device = new device.Device();3var deviceLogs = device.restoreLogs('device-uuid');4console.log(deviceLogs);5var device = require('devicefarmer-stf-device');6var device = new device.Device();7var deviceLogs = device.restoreLogs('device-uuid');8console.log(deviceLogs);9var device = require('devicefarmer-stf-device');10var device = new device.Device();11var deviceLogs = device.restoreLogs('device-uuid');12console.log(deviceLogs);13var device = require('devicefarmer-stf-device');14var device = new device.Device();15var deviceLogs = device.restoreLogs('device-uuid');16console.log(deviceLogs);17var device = require('devicefarmer-stf-device');18var device = new device.Device();19var deviceLogs = device.restoreLogs('device-uuid');20console.log(deviceLogs);21var device = require('devicefarmer-stf-device');22var device = new device.Device();23var deviceLogs = device.restoreLogs('device-uuid');24console.log(deviceLogs);25var device = require('devicefarmer-stf-device');26var device = new device.Device();27var deviceLogs = device.restoreLogs('device-uuid');28console.log(deviceLogs);29var device = require('devicefarmer-stf-device');30var device = new device.Device();31var deviceLogs = device.restoreLogs('device-uuid');32console.log(deviceLogs);33var device = require('devicefarmer-stf-device');34var device = new device.Device();35var deviceLogs = device.restoreLogs('device-uuid');
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!!