|
| 1 | +import * as fs from "fs"; |
| 2 | +import * as assert from "assert"; |
| 3 | + |
| 4 | +import { CertificateClient } from "../lib"; |
| 5 | +import { CertificateInterface } from "../lib/certificate"; |
| 6 | + |
| 7 | +class TestCertificateClient implements CertificateInterface { |
| 8 | + certsDirPath(): string { |
| 9 | + return "./tmp"; |
| 10 | + } |
| 11 | + |
| 12 | + certKeyPath(): string { |
| 13 | + return `${this.certsDirPath()}/cert.txt`; |
| 14 | + } |
| 15 | + |
| 16 | + privateKeyPath(): string { |
| 17 | + return `${this.certsDirPath()}/private.txt`; |
| 18 | + } |
| 19 | + |
| 20 | + publicKeyPath(): string { |
| 21 | + return `${this.certsDirPath()}/public.txt`; |
| 22 | + } |
| 23 | + |
| 24 | + rootKeyPath(): string { |
| 25 | + return `${this.certsDirPath()}/root.txt`; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +describe("@teitei-tk/bravia-aws-package", () => { |
| 30 | + describe("CertificateClient", () => { |
| 31 | + let client: CertificateClient; |
| 32 | + beforeAll(() => { |
| 33 | + client = new CertificateClient(new TestCertificateClient()); |
| 34 | + |
| 35 | + // mkdir |
| 36 | + const mkdirReuslt = fs.mkdirSync(client.certsDirPath()); |
| 37 | + assert.equal(mkdirReuslt, undefined); |
| 38 | + |
| 39 | + const certKeyResult = fs.writeFileSync(client.certKeyPath(), ""); |
| 40 | + assert.equal(certKeyResult, undefined); |
| 41 | + |
| 42 | + const privateKeyResult = fs.writeFileSync(client.privateKeyPath(), ""); |
| 43 | + assert.equal(privateKeyResult, undefined); |
| 44 | + |
| 45 | + const publicKeyResult = fs.writeFileSync(client.publicKeyPath(), ""); |
| 46 | + assert.equal(publicKeyResult, undefined); |
| 47 | + |
| 48 | + const rootKeyResult = fs.writeFileSync(client.rootKeyPath(), ""); |
| 49 | + assert.equal(rootKeyResult, undefined); |
| 50 | + }); |
| 51 | + |
| 52 | + afterAll(() => { |
| 53 | + const certKeyResult = fs.unlinkSync(client.certKeyPath()); |
| 54 | + assert.equal(certKeyResult, undefined); |
| 55 | + |
| 56 | + const privateKeyResult = fs.unlinkSync(client.privateKeyPath()); |
| 57 | + assert.equal(privateKeyResult, undefined); |
| 58 | + |
| 59 | + const publicKeyResult = fs.unlinkSync(client.publicKeyPath()); |
| 60 | + assert.equal(publicKeyResult, undefined); |
| 61 | + |
| 62 | + const rootKeyResult = fs.unlinkSync(client.rootKeyPath()); |
| 63 | + assert.equal(rootKeyResult, undefined); |
| 64 | + |
| 65 | + // rmdir |
| 66 | + const result = fs.rmdirSync(client.certsDirPath()); |
| 67 | + assert.equal(result, undefined); |
| 68 | + }); |
| 69 | + |
| 70 | + it("certs dir exists?", () => { |
| 71 | + const result = fs.existsSync(client.certsDirPath()); |
| 72 | + expect(result).toBeTruthy(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("certs key exists?", () => { |
| 76 | + const result = fs.existsSync(client.certKeyPath()); |
| 77 | + expect(result).toBeTruthy(); |
| 78 | + }); |
| 79 | + |
| 80 | + it("private key exists?", () => { |
| 81 | + const result = fs.existsSync(client.privateKeyPath()); |
| 82 | + expect(result).toBeTruthy(); |
| 83 | + }); |
| 84 | + |
| 85 | + it("public key exists?", () => { |
| 86 | + const result = fs.existsSync(client.publicKeyPath()); |
| 87 | + expect(result).toBeTruthy(); |
| 88 | + }); |
| 89 | + |
| 90 | + it("root key exists?", () => { |
| 91 | + const result = fs.existsSync(client.rootKeyPath()); |
| 92 | + expect(result).toBeTruthy(); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments