diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c4f4154 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 0000000..79f1f4a --- /dev/null +++ b/.github/workflows/unittests.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 036b2cf..3dfc94b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 3fcbde6..0a0cbda 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ test: - pytest . + poetry run pytest . -vv fmt: - black . + poetry run black . fmt-check: - black --check . + poetry run black --check . diff --git a/TestConfig.yaml b/TestConfig.yaml index 020294d..ee447e3 100644 --- a/TestConfig.yaml +++ b/TestConfig.yaml @@ -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 diff --git a/docs/README.md b/docs/overview.md similarity index 100% rename from docs/README.md rename to docs/overview.md diff --git a/plugin/plugin.py b/plugin/plugin.py index 05feaa9..7e0e46a 100644 --- a/plugin/plugin.py +++ b/plugin/plugin.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 5923734..fa6ff53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "" authors = ["Plaintextnerds "] readme = "README.md" -packages = [{include = "plugin"}] +packages = [{ include = "plugin" }] [tool.poetry.dependencies] python = ">=3.11,<3.14" @@ -20,4 +20,3 @@ main = "main:main" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" - diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..7dab082 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = tests/*.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/package.py b/tests/package.py new file mode 100644 index 0000000..712d2a3 --- /dev/null +++ b/tests/package.py @@ -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" + )