diff --git a/.github/workflows/deploy-ci.yaml b/.github/workflows/deploy-ci.yaml index d9f8361..815ea86 100644 --- a/.github/workflows/deploy-ci.yaml +++ b/.github/workflows/deploy-ci.yaml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest services: rabbitmq: - image: rabbitmq:3-alpine + image: rabbitmq:3.13.3-alpine ports: - 5672:5672 strategy: @@ -34,6 +34,8 @@ jobs: run: npm run lint:fix - name: Run Unit Tests run: npm run test + env: + RABBITMQ_URL: amqp://guest:guest@localhost:5672 Release: runs-on: ubuntu-latest needs: [ 'Test' ] diff --git a/.github/workflows/pr-unit-tests.yml b/.github/workflows/pr-unit-tests.yml index 337379b..d9c1082 100644 --- a/.github/workflows/pr-unit-tests.yml +++ b/.github/workflows/pr-unit-tests.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest services: rabbitmq: - image: rabbitmq:3-alpine + image: rabbitmq:3.13.3-alpine ports: - 5672:5672 strategy: @@ -34,6 +34,8 @@ jobs: run: npm run lint:fix - name: Run Unit Tests run: npm run test + env: + RABBITMQ_URL: amqp://guest:guest@localhost:5672 - name: Check test results run: exit ${{ steps.Test.outputs.test_result }} id: check_test_result diff --git a/__tests__/app.test.ts b/__tests__/app.test.ts index b7a0d36..8dfc262 100644 --- a/__tests__/app.test.ts +++ b/__tests__/app.test.ts @@ -4,6 +4,8 @@ import { describe, expect, test, beforeEach, afterEach } from 'vitest' import fastifyRabbit from '../src' import { createDeferred, expectEvent, sleep } from './__utils__/utils' +const RABBITMQ_URL = process.env.RABBITMQ_URL || `amqp://guest:guest@localhost` + describe('fastify-rabbitmq sample app tests', () => { describe('no namespace', () => { let app: FastifyInstance @@ -14,7 +16,7 @@ describe('fastify-rabbitmq sample app tests', () => { app = fastify() await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost' + connection: RABBITMQ_URL }) await app.listen() @@ -95,7 +97,7 @@ describe('fastify-rabbitmq sample app tests', () => { app = fastify() await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, namespace: 'unittest' }) diff --git a/__tests__/rabbitmq.test.ts b/__tests__/rabbitmq.test.ts index 7c88dd2..997c517 100644 --- a/__tests__/rabbitmq.test.ts +++ b/__tests__/rabbitmq.test.ts @@ -5,6 +5,8 @@ import { errors } from '../src/errors' let app: FastifyInstance +const RABBITMQ_URL = process.env.RABBITMQ_URL || `amqp://guest:guest@localhost` + beforeEach(() => { app = fastify() }) @@ -59,11 +61,11 @@ describe('plugin fastify-rabbitmq tests', () => { test("register - can't be registered twice", async () => { try { await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost' + connection: RABBITMQ_URL }) await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost' + connection: RABBITMQ_URL }) } catch (err) { expect(err).toEqual(new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS('Already registered.')) @@ -73,12 +75,12 @@ describe('plugin fastify-rabbitmq tests', () => { test("register - can't be registered twice - namespace", async () => { try { await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, namespace: 'error' }) await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, namespace: 'error' }) } catch (err) { @@ -112,7 +114,7 @@ describe('plugin fastify-rabbitmq tests', () => { test('ensure basic properties are accessible via namespace', async () => { try { await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, namespace: 'unittest' }).ready().then(async () => { expect(app.rabbitmq.unittest).toHaveProperty('acquire') @@ -135,7 +137,7 @@ describe('plugin fastify-rabbitmq tests', () => { test('register with log level: debug', async () => { try { await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, logLevel: 'debug' }).ready().then(async () => { expect(app.rabbitmq.unittest).toHaveProperty('createConsumer') @@ -149,7 +151,7 @@ describe('plugin fastify-rabbitmq tests', () => { test('register with log level: trace', async () => { try { await app.register(fastifyRabbit, { - connection: 'amqp://guest:guest@localhost', + connection: RABBITMQ_URL, logLevel: 'trace' }).ready().then(async () => { expect(app.rabbitmq.unittest).toHaveProperty('createConsumer') @@ -159,25 +161,5 @@ describe('plugin fastify-rabbitmq tests', () => { /* should not error */ } }) - - test('host does not exist', async () => { - try { - await app.register(fastifyRabbit, { - connection: 'amqp://doesnotexist' - }) - } catch (e) { - expect(e).toBeTruthy() - } - }) - - test('invalid protocol', async () => { - try { - await app.register(fastifyRabbit, { - connection: 'xamqp://localhost' - }) - } catch (e) { - expect(e).toBeTruthy() - } - }) }) })