Skip to content

Commit

Permalink
New Plugin Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamshale committed Apr 18, 2024
1 parent 1fae7f2 commit 66f9e6c
Show file tree
Hide file tree
Showing 17 changed files with 3,119 additions and 0 deletions.
22 changes: 22 additions & 0 deletions new_plugin/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.134.0/containers/python-3/.devcontainer/base.Dockerfile
ARG VARIANT="3.9-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

ARG POETRY_VERSION="1.7.1"
ENV POETRY_HOME="/opt/poetry" \
POETRY_VERSION=${POETRY_VERSION}

RUN curl -sSL https://install.python-poetry.org | python3 - \
&& update-alternatives --install /usr/local/bin/poetry poetry /opt/poetry/bin/poetry 900 \
# Enable tab completion for bash
&& poetry completions bash >> /home/vscode/.bash_completion \
# Enable tab completion for Zsh
&& mkdir -p /home/vscode/.zfunc/ \
&& poetry completions zsh > /home/vscode/.zfunc/_poetry \
&& echo "fpath+=~/.zfunc\nautoload -Uz compinit && compinit" >> /home/vscode/.zshrc

COPY pyproject.toml ./
# COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --no-interaction --with integration --extras "aca-py" \
&& rm -rf /root/.cache/pypoetry
50 changes: 50 additions & 0 deletions new_plugin/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "new_plugin",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "3.9-bullseye",
"POETRY_VERSION": "1.7.1"
}
},
"customizations": {
"vscode": {
"extensions": ["ms-python.python", "ms-python.vscode-pylance"],
"settings": {
"python.testing.pytestArgs": ["./new_plugin", "--no-cov"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestPath": "pytest",
"editor.defaultFormatter": null,
"editor.formatOnSave": false, // enable per language
"[python]": {
"editor.formatOnSave": true
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.blackArgs": []
}
}
},

"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": false
}
},

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",

"remoteEnv": {
"RUST_LOG": "aries-askar::log::target=error"
},

"mounts": [],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 3001],
"postCreateCommand": "bash ./.devcontainer/post-install.sh"
}
14 changes: 14 additions & 0 deletions new_plugin/.devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ex

# Convenience workspace directory for later use
WORKSPACE_DIR=$(pwd)

# install all ACA-Py requirements
python -m pip install --upgrade pip

# install black for formatting
pip3 install black

# Generate Poetry Lock file
poetry lock --no-update
38 changes: 38 additions & 0 deletions new_plugin/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run/Debug Plugin",
"type": "python",
"request": "launch",
"module": "aries_cloudagent",
"justMyCode": false,
"args": ["start", "--arg-file=${workspaceRoot}/docker/default.yml"]
},
{
"name": "ruff - new_plugin",
"type": "python",
"request": "launch",
"module": "ruff",
"console": "integratedTerminal",
"sudo": true,
"justMyCode": true,
"cwd": "${workspaceFolder}/new_plugin",
"args": ["check", "."]
},
{
"name": "ruff fix - new_plugin",
"type": "python",
"request": "launch",
"module": "ruff",
"console": "integratedTerminal",
"sudo": true,
"justMyCode": true,
"cwd": "${workspaceFolder}/new_plugin",
"args": ["check", ".", "--fix"]
}
]
}
7 changes: 7 additions & 0 deletions new_plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Description:

< Replace with information about the reason this plugin was produced and a brief overview of the features >

### Configuration:

< Replace this section with an outline of configuation options and basic defaults for deploying the plugin >
31 changes: 31 additions & 0 deletions new_plugin/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.9-slim AS base
WORKDIR /usr/src/app

# Install and configure poetry
USER root

ENV POETRY_VERSION=1.7.1
ENV POETRY_HOME=/opt/poetry
RUN apt-get update && apt-get install -y curl && apt-get clean
RUN curl -sSL https://install.python-poetry.org | python -

ENV PATH="/opt/poetry/bin:$PATH"
RUN poetry config virtualenvs.in-project true

# Setup project
RUN mkdir new_plugin && touch new_plugin/__init__.py
COPY pyproject.toml poetry.lock README.md ./
ARG install_flags='--with integration --extras aca-py'
RUN poetry install ${install_flags}
USER $user

FROM python:3.9-bullseye
WORKDIR /usr/src/app
COPY --from=base /usr/src/app/.venv /usr/src/app/.venv
ENV PATH="/usr/src/app/.venv/bin:$PATH"

COPY new_plugin/ new_plugin/
COPY docker/*.yml ./

ENTRYPOINT ["/bin/bash", "-c", "aca-py \"$@\"", "--"]
CMD ["start", "--arg-file", "default.yml"]
22 changes: 22 additions & 0 deletions new_plugin/docker/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
label: new_plugin

admin: [0.0.0.0, 3001]
admin-insecure-mode: false
admin-api-key: change-me

inbound-transport:
- [http, 0.0.0.0, 3000]
- [ws, 0.0.0.0, 3002]
outbound-transport: http
endpoint:
- http://host.docker.internal:3000

plugin:
- new_plugin.v1_0

genesis-url: http://test.bcovrin.vonx.io/genesis

log-level: info

auto-accept-invites: true
auto-respond-messages: true
20 changes: 20 additions & 0 deletions new_plugin/docker/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
label: new_plugin

admin: [0.0.0.0, 3001]
admin-insecure-mode: true

inbound-transport:
- [http, 0.0.0.0, 3000]
outbound-transport: http
endpoint:
- http://host.docker.internal:3000

plugin:
- new_plugin.v1_0

genesis-url: http://test.bcovrin.vonx.io/genesis

log-level: info

auto-accept-invites: true
auto-respond-messages: true
20 changes: 20 additions & 0 deletions new_plugin/integration/Dockerfile.test.runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.9-slim
WORKDIR /usr/src/app

# install poetry
RUN pip3 install --no-cache-dir poetry

# Add docker-compose-wait tool
ENV WAIT_VERSION 2.7.2
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
RUN chmod +x /wait

# install dependencies
COPY pyproject.toml .
COPY poetry.lock .
RUN poetry install --only main

# add tests to image
COPY tests/* tests/

ENTRYPOINT ["/bin/sh", "-c", "/wait && poetry run pytest \"$@\"", "--"]
14 changes: 14 additions & 0 deletions new_plugin/integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Integration Tests

All plugins should have a suite of integration tests. We use `docker compose` to set up the environment, and make use of the [Dockerfile](../docker/Dockerfile) to produce our ACA-Py/Plugin image. To simplify, we have another [Dockerfile](Dockerfile.test.runner) for running those [tests](/tests/).

## Build and run Tests

The integration tests will start 2 agents - bob and alice - and a juggernaut container that will execute the tests. Test results will be found in the juggernaut container output. The juggernaut container should close itself down, the logs can be reviewed in the `Docker` view, open `Containers`, open `integration`, right-click the `integration-tests` container and select `View Logs`

```sh
# open a terminal in vs code
cd integration
docker compose build
docker compose up
```
33 changes: 33 additions & 0 deletions new_plugin/integration/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
#***************************************************************
# integration level test agents *
#***************************************************************

services:
bob:
image: plugin-image
build:
context: ..
dockerfile: docker/Dockerfile
args:
- install_flags=--no-interaction --with integration --extras aca-py
command: start --arg-file integration.yml --label bob -e http://bob:3000 --log-level debug

alice:
image: plugin-image
command: start --arg-file integration.yml --label alice -e http://alice:3000 --log-level debug

tests:
container_name: juggernaut
build:
context: .
dockerfile: Dockerfile.test.runner
environment:
- WAIT_BEFORE_HOSTS=3
- WAIT_HOSTS=bob:3000, alice:3000
- WAIT_HOSTS_TIMEOUT=60
- WAIT_SLEEP_INTERVAL=1
- WAIT_HOST_CONNECT_TIMEOUT=30
depends_on:
- bob
- alice
18 changes: 18 additions & 0 deletions new_plugin/integration/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "plugin-globals-tests"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.9"
pytest = "^7.4.0"
pytest-asyncio = "^0.21.0"
asynctest = "^0.13.0"
requests = "^2.31.0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Loading

0 comments on commit 66f9e6c

Please sign in to comment.