UNPKG

7.95 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10var __generator = (this && this.__generator) || function (thisArg, body) {
11 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13 function verb(n) { return function (v) { return step([n, v]); }; }
14 function step(op) {
15 if (f) throw new TypeError("Generator is already executing.");
16 while (_) try {
17 if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
18 if (y = 0, t) op = [0, t.value];
19 switch (op[0]) {
20 case 0: case 1: t = op; break;
21 case 4: _.label++; return { value: op[1], done: false };
22 case 5: _.label++; y = op[1]; op = [0]; continue;
23 case 7: op = _.ops.pop(); _.trys.pop(); continue;
24 default:
25 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29 if (t[2]) _.ops.pop();
30 _.trys.pop(); continue;
31 }
32 op = body.call(thisArg, _);
33 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35 }
36};
37var _this = this;
38Object.defineProperty(exports, "__esModule", { value: true });
39var Environment_1 = require("./Environment");
40var Output_1 = require("./Output");
41var Config_1 = require("./Config");
42// lets write some tests
43function makeEnvironment() {
44 var config = new Config_1.Config();
45 var out = new Output_1.Output(config);
46 return new Environment_1.Environment(out, config);
47}
48describe('environment', function () {
49 test('should work without global RC', function () { return __awaiter(_this, void 0, void 0, function () {
50 var env, localFile;
51 return __generator(this, function (_a) {
52 switch (_a.label) {
53 case 0:
54 env = makeEnvironment();
55 localFile = "\nplatformToken: 'secret-token'\ntargets:\n dev: local/asdasd123\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n";
56 return [4 /*yield*/, env.loadRCs(localFile, null)];
57 case 1:
58 _a.sent();
59 expect(env.rc).toMatchSnapshot();
60 return [2 /*return*/];
61 }
62 });
63 }); });
64 test('should resolve a target alias refering before', function () { return __awaiter(_this, void 0, void 0, function () {
65 var env, localFile;
66 return __generator(this, function (_a) {
67 switch (_a.label) {
68 case 0:
69 env = makeEnvironment();
70 localFile = "\nplatformToken: 'secret-token'\ntargets:\n dev: local/asdasd123\n test-alias: dev\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n";
71 return [4 /*yield*/, env.loadRCs(localFile, null)];
72 case 1:
73 _a.sent();
74 expect(env.rc).toMatchSnapshot();
75 return [2 /*return*/];
76 }
77 });
78 }); });
79 test('should resolve a target alias refering after', function () { return __awaiter(_this, void 0, void 0, function () {
80 var env, localFile;
81 return __generator(this, function (_a) {
82 switch (_a.label) {
83 case 0:
84 env = makeEnvironment();
85 localFile = "\nplatformToken: 'secret-token'\ntargets:\n test-alias: dev\n dev: local/asdasd123\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n";
86 return [4 /*yield*/, env.loadRCs(localFile, null)];
87 case 1:
88 _a.sent();
89 expect(env.rc).toMatchSnapshot();
90 return [2 /*return*/];
91 }
92 });
93 }); });
94 //
95 // test('throws when cluster does not exist', async () => {
96 // const env = makeEnvironment()
97 // const localFile = `
98 // platformToken: 'secret-token'
99 // targets:
100 // dev: local/asdasd123
101 // `
102 // env.loadRCs(localFile, null)
103 // await expect(env.out.stderr.output).toMatch(/Could not find cluster local defined for target dev in/)
104 // })
105 test('should access targets from the global RC', function () { return __awaiter(_this, void 0, void 0, function () {
106 var env, localFile, globalFile;
107 return __generator(this, function (_a) {
108 switch (_a.label) {
109 case 0:
110 env = makeEnvironment();
111 localFile = "\nplatformToken: 'secret-token'\ntargets:\n test-alias: dev\n dev: local/asdasd123\n";
112 globalFile = "\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n ";
113 return [4 /*yield*/, env.loadRCs(localFile, globalFile)];
114 case 1:
115 _a.sent();
116 expect(env.rc).toMatchSnapshot();
117 return [2 /*return*/];
118 }
119 });
120 }); });
121 test('should resolve target from the global RC', function () { return __awaiter(_this, void 0, void 0, function () {
122 var env, localFile, globalFile;
123 return __generator(this, function (_a) {
124 switch (_a.label) {
125 case 0:
126 env = makeEnvironment();
127 localFile = "\nplatformToken: 'secret-token'\ntargets:\n test-alias: dev\n";
128 globalFile = "\ntargets:\n dev: local/asdasd123\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n ";
129 return [4 /*yield*/, env.loadRCs(localFile, globalFile)];
130 case 1:
131 _a.sent();
132 expect(env.rc).toMatchSnapshot();
133 return [2 /*return*/];
134 }
135 });
136 }); });
137 test('should override global target', function () { return __awaiter(_this, void 0, void 0, function () {
138 var env, localFile, globalFile;
139 return __generator(this, function (_a) {
140 switch (_a.label) {
141 case 0:
142 env = makeEnvironment();
143 localFile = "\nplatformToken: 'secret-token'\ntargets:\n dev: shared-eu-west-1/asdfasdf\n";
144 globalFile = "\ntargets:\n dev: local/asdasd123\nclusters:\n local:\n host: http://localhost:60000\n token: asdf\n ";
145 return [4 /*yield*/, env.loadRCs(localFile, globalFile)];
146 case 1:
147 _a.sent();
148 expect(env.rc).toMatchSnapshot();
149 return [2 /*return*/];
150 }
151 });
152 }); });
153});
154//# sourceMappingURL=Environment.test.js.map
\No newline at end of file