Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps #57

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: npm

- name: Install Dependencies
Expand Down
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: npm

- name: Install Dependencies
Expand All @@ -40,25 +40,25 @@ jobs:
id: npm-ci-test
run: npm run ci-test

test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest
# test-action:
# name: GitHub Actions Test
# runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
# steps:
# - name: Checkout
# id: checkout
# uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: ./
with:
subject: 'github.actions.test'
message: '{"action": "action-nats-publish"}'
urls: tls://connect.ngs.global
jwt: ${{ secrets.NATS_CLIENT_JWT }}
nKeySeed: ${{ secrets.NATS_NKEY_SEED }}
# - name: Test Local Action
# id: test-action
# uses: ./
# with:
# subject: 'github.actions.test'
# message: '{"action": "action-nats-publish"}'
# urls: tls://connect.ngs.global
# jwt: ${{ secrets.NATS_CLIENT_JWT }}
# nKeySeed: ${{ secrets.NATS_NKEY_SEED }}

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.published }}"
# - name: Print Output
# id: output
# run: echo "${{ steps.test-action.outputs.published }}"
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: npm

- name: Install Dependencies
Expand Down
46 changes: 44 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as main from '../src/main'
// Mock the GitHub Actions core library
const debugMock = jest.spyOn(core, 'debug')
const getInputMock = jest.spyOn(core, 'getInput')
// const setFailedMock = jest.spyOn(core, 'setFailed')
const setFailedMock = jest.spyOn(core, 'setFailed')
const setOutputMock = jest.spyOn(core, 'setOutput')

// Mock the action's main function
Expand All @@ -31,7 +31,7 @@ describe('action', () => {
urls: 'nats://localhost:4222',
message: '{"test": 1234}',
nKeySeed: 'SNOTAREALNKEYSEED',
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' // gitleaks:allow
}

it('Connects to NATS', async () => {
Expand Down Expand Up @@ -74,6 +74,10 @@ describe('action', () => {
// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(
1,
'connecting to:\nnats://localhost:4222'
)
expect(debugMock).toHaveBeenNthCalledWith(
2,
`NATS connected to nats://localhost:4222`
)
expect(setOutputMock).toHaveBeenNthCalledWith(
Expand All @@ -82,4 +86,42 @@ describe('action', () => {
`subject: subject.test, message: {"test": 1234}`
)
})

it('Fails when a connection error occurs', async () => {
// Mock the NATS connection
const mockConnectImpl = async (): Promise<nats.NatsConnection> => {
throw new Error('Invalid URL')
}

connectMock.mockImplementation(mockConnectImpl)

await main.run()
expect(runMock).toHaveReturned()

expect(setFailedMock).toHaveBeenNthCalledWith(1, 'Invalid URL')
})

it('Fails when a connection close error occurs', async () => {
// Mock the NATS connection
const mockConnectImpl = async (): Promise<nats.NatsConnection> => {
return {
info: { server_name: 'nats://localhost:4222' },
publish: jest.fn(),
close: jest.fn(),
// Yes, closed() returns an Error rather than throwing one
closed: async () => new Error('connection already closed'),
drain: jest.fn()
} as unknown as nats.NatsConnection
}

connectMock.mockImplementation(mockConnectImpl)

await main.run()
expect(runMock).toHaveReturned()

expect(debugMock).toHaveBeenNthCalledWith(
5,
'error closing:\nconnection already closed'
)
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 54 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "typescript-action",
"description": "GitHub Actions TypeScript template",
"version": "0.0.1-0",
"author": "",
"name": "action-nats-publish",
"description": "Publish a message to NATS servers",
"version": "0.0.2-0",
"author": "OperationSpark",
"private": true,
"homepage": "https://github.com/actions/typescript-action",
"homepage": "https://github.com/OperationSpark/action-nats-publish",
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/OperationSpark/action-nats-publish.git"
},
"bugs": {
"url": "https://github.com/actions/typescript-action/issues"
"url": "https://github.com/OperationSpark/action-nats-publish/issues"
},
"keywords": [
"actions",
Expand Down
Loading
Loading