|
| 1 | +/** |
| 2 | + * Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 3 | + * Licensed under the GNU Affero General Public License (AGPL). |
| 4 | + * See License.AGPL.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { suite, test } from "@testdeck/mocha"; |
| 8 | +import * as chai from "chai"; |
| 9 | +import { RedisPublisher } from "./publisher"; |
| 10 | +import { Metrics } from "../metrics"; |
| 11 | +import { RedisClient } from "./client"; |
| 12 | +import { Container, ContainerModule } from "inversify"; |
| 13 | + |
| 14 | +const expect = chai.expect; |
| 15 | +const Redis = require("ioredis-mock"); |
| 16 | + |
| 17 | +@suite |
| 18 | +class TestRedisPublisher { |
| 19 | + protected container: Container; |
| 20 | + |
| 21 | + public before() { |
| 22 | + const client = { |
| 23 | + get: () => new Redis(), |
| 24 | + } as RedisClient; |
| 25 | + |
| 26 | + this.container = new Container(); |
| 27 | + this.container.load( |
| 28 | + new ContainerModule((bind) => { |
| 29 | + bind(Metrics).toSelf().inSingletonScope(); |
| 30 | + bind(RedisClient).toConstantValue(client); |
| 31 | + bind(RedisPublisher).toSelf().inSingletonScope(); |
| 32 | + }), |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + @test public publishInstanceUpdate() { |
| 37 | + const publisher = this.container.get(RedisPublisher); |
| 38 | + expect(() => { |
| 39 | + publisher.publishInstanceUpdate({ |
| 40 | + ownerID: "123-owner", |
| 41 | + instanceID: "123", |
| 42 | + workspaceID: "foo-bar-123", |
| 43 | + }); |
| 44 | + }).not.to.throw; |
| 45 | + } |
| 46 | +} |
| 47 | +module.exports = new TestRedisPublisher(); |
0 commit comments