Skip to content
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
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint with Black

on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip3 install --no-cache-dir poetry==2.1.4
poetry install --no-interaction --no-ansi --no-root
- name: Check formatting
run: make fmt-check
30 changes: 30 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
pull_request:
push:
branches:
- main

jobs:
test:
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- # Required for the package command tests to work
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip3 install --no-cache-dir poetry==2.1.4
poetry install --no-interaction --no-ansi --no-root
- name: Run tests
run: make test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /app
# Copy requirements.txt and install the Python dependencies
COPY pyproject.toml .
COPY poetry.lock .
RUN pip3 install --no-cache-dir poetry
RUN pip3 install --no-cache-dir poetry==2.1.4
RUN poetry install --no-interaction --no-ansi --no-root

# Copy the rest of the code
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test:
pytest .
poetry run pytest . -vv

fmt:
black .
poetry run black .

fmt-check:
black --check .
poetry run black --check .
2 changes: 1 addition & 1 deletion TestConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ kind: destination
spec:
name: sqlite
path: cloudquery/sqlite
version: "v2.4.11"
version: "v2.4.11" # latest version of destination sqlite plugin
spec:
connection_string: ./db.sqlite
File renamed without changes.
4 changes: 3 additions & 1 deletion plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class ExamplePlugin(plugin.Plugin):
def __init__(self) -> None:
super().__init__(
PLUGIN_NAME, PLUGIN_VERSION, plugin.plugin.Options(team=TEAM_NAME, kind=PLUGIN_KIND)
PLUGIN_NAME,
PLUGIN_VERSION,
plugin.plugin.Options(team=TEAM_NAME, kind=PLUGIN_KIND),
)
self._spec_json = None
self._spec = None
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = ""
authors = ["Plaintextnerds <[email protected]>"]
readme = "README.md"
packages = [{include = "plugin"}]
packages = [{ include = "plugin" }]

[tool.poetry.dependencies]
python = ">=3.11,<3.14"
Expand All @@ -20,4 +20,3 @@ main = "main:main"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
python_files = tests/*.py
Empty file added tests/__init__.py
Empty file.
88 changes: 88 additions & 0 deletions tests/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import os
from cloudquery.sdk import serve
from plugin import ExamplePlugin


def test_plugin_package():
p = ExamplePlugin()
cmd = serve.PluginCommand(p)
cmd.run(["package", "-m", "test", "v0.0.1", "."])
assert os.path.isfile("dist/tables.json")
assert os.path.isfile("dist/package.json")
assert os.path.isfile("dist/docs/overview.md")
assert os.path.isfile("dist/plugin-example-v0.0.1-linux-amd64.tar")
assert os.path.isfile("dist/plugin-example-v0.0.1-linux-arm64.tar")

with open("dist/tables.json", "r") as f:
tables = json.loads(f.read())
assert tables == [
{
"name": "example_item",
"title": "Example Item",
"description": "",
"is_incremental": False,
"parent": "",
"relations": [],
"columns": [
{
"name": "num",
"type": "uint64",
"description": "",
"incremental_key": False,
"primary_key": True,
"not_null": False,
"unique": False,
},
{
"name": "string",
"type": "string",
"description": "",
"incremental_key": False,
"primary_key": False,
"not_null": False,
"unique": False,
},
{
"name": "date",
"type": "date64[ms]",
"description": "",
"incremental_key": False,
"primary_key": False,
"not_null": False,
"unique": False,
},
],
},
]
with open("dist/package.json", "r") as f:
package = json.loads(f.read())
assert package["schema_version"] == 1
assert package["name"] == "example"
assert package["version"] == "v0.0.1"
assert package["team"] == "cloudquery"
assert package["kind"] == "source"
assert package["message"] == "test"
assert package["protocols"] == [3]
assert len(package["supported_targets"]) == 2
assert package["package_type"] == "docker"
assert package["supported_targets"][0]["os"] == "linux"
assert package["supported_targets"][0]["arch"] == "amd64"
assert (
package["supported_targets"][0]["path"]
== "plugin-example-v0.0.1-linux-amd64.tar"
)
assert (
package["supported_targets"][0]["docker_image_tag"]
== "docker.cloudquery.io/cloudquery/source-example:v0.0.1-linux-amd64"
)
assert package["supported_targets"][1]["os"] == "linux"
assert package["supported_targets"][1]["arch"] == "arm64"
assert (
package["supported_targets"][1]["path"]
== "plugin-example-v0.0.1-linux-arm64.tar"
)
assert (
package["supported_targets"][1]["docker_image_tag"]
== "docker.cloudquery.io/cloudquery/source-example:v0.0.1-linux-arm64"
)