Skip to content

Commit

Permalink
Added tests for the notifications plugin.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Oct 1, 2024
1 parent 9771b03 commit 12849b7
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
tests: snapshot
- version: 2.17.0
tests: plugins/streaming
- version: 2.17.0
tests: plugins/notifications
- version: 2.18.0
hub: opensearchstaging
ref: '@sha256:4445e195c53992038891519dc3be0d273cdaad1b047943d68921168ed243e7e9'
Expand Down
1 change: 1 addition & 0 deletions .lycheeignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
https://localhost:*
http://webhook:8080
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added `/_plugins/_ml/agents/_register`, `/_plugins/_ml/connectors/_create`, `DELETE /_plugins/_ml/agents/{agent_id}`, `DELETE /_plugins/_ml/connectors/{connector_id}` ([#228](https://github.com/opensearch-project/opensearch-api-specification/issues/228))
- Added the `context` query param to the `put_script` APIs ([#586](https://github.com/opensearch-project/opensearch-api-specification/pull/586))
- Added `persian_stem` filter ([#592](https://github.com/opensearch-project/opensearch-api-specification/pull/592))
- Added `config_id` and `config_id_list` to `/_plugins/_notifications/configs` query parameters ([#594](https://github.com/opensearch-project/opensearch-api-specification/pull/594))

### Changed

Expand Down Expand Up @@ -169,6 +170,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed create/delete/index operation in `_bulk` ([#582](https://github.com/opensearch-project/opensearch-api-specification/pull/582))
- Add `mode` and `compression` to k-NN index creation and search, and add `rescore` and `oversample_factor` to k-NN search ([#588](https://github.com/opensearch-project/opensearch-api-specification/pull/588))
- Fixed `/{index}/_search` with aggregations ([#576](https://github.com/opensearch-project/opensearch-api-specification/pull/576))
- Fixed `RestStatus` responses in `DELETE /_plugins/_notifications/configs/{config_id}` ([#594](https://github.com/opensearch-project/opensearch-api-specification/pull/594))

### Security

Expand Down
16 changes: 16 additions & 0 deletions spec/namespaces/notifications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ paths:
parameters:
- $ref: '#/components/parameters/notifications.get_configs::query.chime.url'
- $ref: '#/components/parameters/notifications.get_configs::query.chime.url.keyword'
- $ref: '#/components/parameters/notifications.get_configs::query.config_id'
- $ref: '#/components/parameters/notifications.get_configs::query.config_id_list'
- $ref: '#/components/parameters/notifications.get_configs::query.config_type'
- $ref: '#/components/parameters/notifications.get_configs::query.created_time_ms'
- $ref: '#/components/parameters/notifications.get_configs::query.description'
Expand Down Expand Up @@ -318,6 +320,20 @@ components:
in: query
schema:
type: string
notifications.get_configs::query.config_id:
name: config_id
in: query
description: Notification configuration ID.
schema:
type: string
notifications.get_configs::query.config_id_list:
name: config_id_list
in: query
description: Notification configuration IDs.
schema:
type: array
items:
type: string
notifications.get_configs::query.config_type:
name: config_type
in: query
Expand Down
25 changes: 8 additions & 17 deletions spec/schemas/notifications._common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,14 @@ components:
RestStatus:
type: string
enum:
- accepted
- continue
- created
- found
- moved_permanently
- multi_status
- multiple_choices
- no_content
- non_authoritative_information
- not_modified
- ok
- partial_content
- reset_content
- see_other
- switching_protocols
- temporary_redirect
- use_proxy
- ACCEPTED
- CREATED
- MULTI_STATUS
- NON_AUTHORITATIVE_INFORMATION
- NO_CONTENT
- OK
- PARTIAL_CONTENT
- RESET_CONTENT
NotificationConfigType:
type: string
description: Type of notification configuration.
Expand Down
9 changes: 9 additions & 0 deletions tests/default/notifications/channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test listing channels.
chapters:
- synopsis: Retrieve a list of all notification channels.
path: /_plugins/_notifications/channels
method: GET
response:
status: 200
96 changes: 96 additions & 0 deletions tests/default/notifications/configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test listing notification configs.
chapters:
- synopsis: Create a Slack channel configuration.
path: /_plugins/_notifications/configs
method: POST
request:
payload:
config_id: slack-configuration
config:
name: Notifications Slack Channel
description: Default notifications channel.
config_type: slack
is_enabled: true
slack:
url: https://example.org/webhook
response:
status: 200
- synopsis: Update a Slack channel configuration.
path: /_plugins/_notifications/configs/{config_id}
method: PUT
parameters:
config_id: slack-configuration
request:
payload:
config:
name: Notifications Slack Channel
config_type: slack
is_enabled: false
slack:
url: https://example.org/webhook
response:
status: 200
- synopsis: Retrieve a list of all notification configurations.
path: /_plugins/_notifications/configs
method: GET
retry:
count: 2
response:
status: 200
payload:
config_list:
- config_id: slack-configuration
- synopsis: Retrieve a list of all notification configurations filtered by config ID.
path: /_plugins/_notifications/configs
method: GET
parameters:
config_type: slack
response:
status: 200
payload:
config_list:
- config_id: slack-configuration
- synopsis: Retrieve a notification configuration by config ID (path).
path: /_plugins/_notifications/configs/{config_id}
method: GET
parameters:
config_id: slack-configuration
response:
status: 200
payload:
config_list:
- config_id: slack-configuration
- synopsis: Retrieve a notification configuration by config ID (query).
path: /_plugins/_notifications/configs
method: GET
parameters:
config_id: slack-configuration
response:
status: 200
payload:
config_list:
- config_id: slack-configuration
- synopsis: Retrieve a notification configuration by config ID list (query).
path: /_plugins/_notifications/configs
method: GET
parameters:
config_id_list:
- slack-configuration
response:
status: 200
payload:
config_list:
- config_id: slack-configuration
- synopsis: Delete a channel configuration.
path: /_plugins/_notifications/configs
method: DELETE
parameters:
config_id: slack-configuration
response:
status: 200
epilogues:
- path: /_plugins/_notifications/configs/slack-configuration
method: DELETE
status: [200,404]
9 changes: 9 additions & 0 deletions tests/default/notifications/features.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test listing supported channel configurations.
chapters:
- synopsis: Retrieve a list of all supported notification configuration types.
path: /_plugins/_notifications/features
method: GET
response:
status: 200
19 changes: 19 additions & 0 deletions tests/plugins/notifications/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'

services:
opensearch-cluster:
image: ${OPENSEARCH_DOCKER_HUB_PROJECT:-opensearchproject}/opensearch:${OPENSEARCH_VERSION:-latest}${OPENSEARCH_DOCKER_REF}
ports:
- 9200:9200
- 9600:9600
environment:
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD:-myStrongPassword123!}
- OPENSEARCH_JAVA_OPTS=${OPENSEARCH_JAVA_OPTS}
- discovery.type=single-node
webhook:
image: python:latest
volumes:
- ./server.py:/server.py
ports:
- '8080:8080'
entrypoint: python server.py
36 changes: 36 additions & 0 deletions tests/plugins/notifications/notifications/feature/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test sending a notification.
prologues:
- path: /_plugins/_notifications/configs
method: POST
request:
payload:
config_id: custom-webhook-configuration
config:
name: Notifications Channel
description: Default notifications channel.
config_type: webhook
is_enabled: true
webhook:
url: http://webhook:8080/
status: [200]
chapters:
- synopsis: Test sending a notification.
path: /_plugins/_notifications/feature/test/{config_id}
method: GET
parameters:
config_id: custom-webhook-configuration
response:
status: 200
payload:
status_list:
- config_id: custom-webhook-configuration
config_type: webhook
delivery_status:
status_code: '200'
status_text: '{"ok":"true"}'
epilogues:
- path: /_plugins/_notifications/configs/custom-webhook-configuration
method: DELETE
status: [200,404]
22 changes: 22 additions & 0 deletions tests/plugins/notifications/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from http.server import BaseHTTPRequestHandler, HTTPServer


class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "application_json")
self.end_headers()
self.wfile.write(b'{"ok":"true"}')

def do_POST(self):
self.send_response(200)
self.send_header("Content-type", "application_json")
self.end_headers()
self.wfile.write(b'{"ok":"true"}')


if __name__ == "__main__":
server_address = ("", 8080)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
print("Server started on http://localhost:8080")
httpd.serve_forever()

0 comments on commit 12849b7

Please sign in to comment.