UNPKG

@apigeeks/fbl-k8s-plugin

Version:

fbl wrapper plugin for helm and kubectl cli utilities

148 lines 7.23 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); const mocha_typescript_1 = require("mocha-typescript"); const typedi_1 = require("typedi"); const fbl_1 = require("fbl"); const kubectl_1 = require("../../../src/handlers/kubectl"); const services_1 = require("../../../src/services"); const K8sBaseHandlerTestSuite_1 = require("../K8sBaseHandlerTestSuite"); chai.use(chaiAsPromised); let K8sDeleteBulkActionHandlerTestSuite = class K8sDeleteBulkActionHandlerTestSuite extends K8sBaseHandlerTestSuite_1.K8sBaseHandlerTestSuite { failValidation() { return __awaiter(this, void 0, void 0, function* () { const actionHandler = new kubectl_1.K8sDeleteBulkActionHandler(); const context = fbl_1.ContextUtil.generateEmptyContext(); const snapshot = new fbl_1.ActionSnapshot('.', {}, '', 0, {}); yield chai.expect(actionHandler.validate([], context, snapshot, {})).to.be.rejected; yield chai.expect(actionHandler.validate({ names: ['test'], }, context, snapshot, {})).to.be.rejected; yield chai.expect(actionHandler.validate({ kind: 'CustomObject', }, context, snapshot, {})).to.be.rejected; yield chai.expect(actionHandler.validate({ kind: 'CustomObject', names: [], }, context, snapshot, {})).to.be.rejected; }); } passValidation() { return __awaiter(this, void 0, void 0, function* () { const actionHandler = new kubectl_1.K8sDeleteBulkActionHandler(); const context = fbl_1.ContextUtil.generateEmptyContext(); const snapshot = new fbl_1.ActionSnapshot('.', {}, '', 0, {}); yield actionHandler.validate({ kind: 'CustomObject', names: ['test-*'], }, context, snapshot, {}); }); } deleteObject() { return __awaiter(this, void 0, void 0, function* () { const applyActionHandler = new kubectl_1.K8sApplyObjectActionHandler(); const deleteActionHandler = new kubectl_1.K8sDeleteBulkActionHandler(); const context = fbl_1.ContextUtil.generateEmptyContext(); const snapshot = new fbl_1.ActionSnapshot('.', {}, '', 0, {}); const deleteObjectOne = { kind: 'ConfigMap', apiVersion: 'v1', data: { test: 'true', }, metadata: { name: 'delete-obj-one', }, }; const deleteObjectTwo = { kind: 'ConfigMap', apiVersion: 'v1', data: { test: 'true', }, metadata: { name: 'delete-obj-two', }, }; const notDeleteObject = { kind: 'ConfigMap', apiVersion: 'v1', data: { test: 'true', }, metadata: { name: 'not-delete-obj', }, }; yield applyActionHandler.execute(deleteObjectOne, context, snapshot, {}); yield applyActionHandler.execute(deleteObjectTwo, context, snapshot, {}); yield applyActionHandler.execute(notDeleteObject, context, snapshot, {}); const configMapsAfterCreate = yield typedi_1.Container.get(services_1.K8sKubectlService).listObjects('ConfigMap'); chai.expect(configMapsAfterCreate) .to.be.an('array') .that.includes('not-delete-obj'); chai.expect(configMapsAfterCreate) .to.be.an('array') .that.includes('delete-obj-one'); chai.expect(configMapsAfterCreate) .to.be.an('array') .that.includes('delete-obj-two'); const deleteContext = fbl_1.ContextUtil.generateEmptyContext(); const deleteSnapshot = new fbl_1.ActionSnapshot('.', {}, '', 0, {}); yield deleteActionHandler.execute({ kind: 'ConfigMap', names: ['delete-obj-*'], }, deleteContext, deleteSnapshot, {}); const configMapsAfterBulkDelete = yield typedi_1.Container.get(services_1.K8sKubectlService).listObjects('ConfigMap'); chai.expect(configMapsAfterBulkDelete) .to.be.an('array') .that.includes('not-delete-obj'); chai.expect(configMapsAfterBulkDelete) .to.be.an('array') .that.not.includes('delete-obj-one'); chai.expect(configMapsAfterBulkDelete) .to.be.an('array') .that.not.includes('delete-obj-two'); }); } }; __decorate([ mocha_typescript_1.test(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], K8sDeleteBulkActionHandlerTestSuite.prototype, "failValidation", null); __decorate([ mocha_typescript_1.test(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], K8sDeleteBulkActionHandlerTestSuite.prototype, "passValidation", null); __decorate([ mocha_typescript_1.test(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], K8sDeleteBulkActionHandlerTestSuite.prototype, "deleteObject", null); K8sDeleteBulkActionHandlerTestSuite = __decorate([ mocha_typescript_1.suite() ], K8sDeleteBulkActionHandlerTestSuite); //# sourceMappingURL=K8sDeleteBulkActionHandlerTestSuite.js.map