UNPKG

4.44 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12// Copyright (C), Siemens AG 2017
13const chai = require("chai");
14require("url-search-params-polyfill");
15const src_1 = require("../src");
16const test_utils_1 = require("./test-utils");
17const rimraf = require("rimraf");
18const _ = require("lodash");
19chai.should();
20describe("Default Storage", () => {
21 const rsaConfig = require("./testconfig.json");
22 process.env.DEBUG = "mindconnect-storage";
23 it("should instantiate.", test_utils_1.mochaAsync(() => __awaiter(void 0, void 0, void 0, function* () {
24 const storage = new src_1.DefaultStorage("./.mochatest/");
25 storage.should.not.be.null;
26 rimraf.sync("./.mochatest/");
27 })));
28 it("should be able to read configuration", test_utils_1.mochaAsync(() => __awaiter(void 0, void 0, void 0, function* () {
29 const storage = new src_1.DefaultStorage("./.mochatest/");
30 const config = yield storage.GetConfig(rsaConfig);
31 config.should.not.be.null;
32 _.isEqual(rsaConfig, config).should.be.true;
33 rimraf.sync("./.mochatest/");
34 })));
35 it("should be able to save configuration", test_utils_1.mochaAsync(() => __awaiter(void 0, void 0, void 0, function* () {
36 const storage = new src_1.DefaultStorage("./.mochatest/");
37 rsaConfig.urls = ["TEST"];
38 const config = yield storage.SaveConfig(rsaConfig);
39 config.should.not.be.null;
40 _.isEqual(rsaConfig, config).should.be.true;
41 config.urls.should.not.be.undefined;
42 config.urls[0].should.equal("TEST");
43 const newConfig = yield storage.GetConfig(rsaConfig);
44 _.isEqual(config, newConfig).should.be.true;
45 newConfig.urls.should.not.be.undefined;
46 newConfig.urls[0].should.equal("TEST");
47 rimraf.sync("./.mochatest/");
48 })));
49 it("should be able to revert configuration if content changes", test_utils_1.mochaAsync(() => __awaiter(void 0, void 0, void 0, function* () {
50 const storage = new src_1.DefaultStorage("./.mochatest/");
51 rsaConfig.urls = ["TEST"];
52 const config = yield storage.SaveConfig(rsaConfig);
53 config.should.not.be.null;
54 _.isEqual(rsaConfig, config).should.be.true;
55 config.urls.should.not.be.undefined;
56 config.urls[0].should.equal("TEST");
57 const newConfig = yield storage.GetConfig(rsaConfig);
58 _.isEqual(config, newConfig).should.be.true;
59 newConfig.urls.should.not.be.undefined;
60 newConfig.urls[0].should.equal("TEST");
61 rsaConfig.content.clientCredentialProfile = ["SHARED_SECRET"];
62 delete rsaConfig.urls;
63 const revertedConfig = yield storage.GetConfig(rsaConfig);
64 (revertedConfig.urls === undefined).should.be.true;
65 rimraf.sync("./.mochatest/");
66 })));
67 it("should be able to syncronize the locks", test_utils_1.mochaAsync(() => __awaiter(void 0, void 0, void 0, function* () {
68 const storage = new src_1.DefaultStorage("./.mochatest/");
69 rsaConfig.urls = ["TEST"];
70 const promises = [];
71 rsaConfig.indexes = [];
72 for (let index = 0; index < 25; index++) {
73 rsaConfig.indexes.push(index);
74 promises.push(yield src_1.retry(5, () => storage.SaveConfig(rsaConfig)));
75 }
76 yield Promise.all(promises);
77 const newConfig = storage.GetConfig(rsaConfig);
78 for (let index = 0; index < newConfig.indexes.length; index++) {
79 const element = rsaConfig.indexes[index];
80 index.should.be.equal(element);
81 }
82 rimraf.sync("./.mochatest/");
83 })));
84});
85//# sourceMappingURL=mindconnect-storage.spec.js.map
\No newline at end of file