Skip to content

Commit

Permalink
fix(docker_test): 修复插件测试获取到的插件元数据主页为空时报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Nov 20, 2024
1 parent f7eee94 commit adaed7f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Fixed

- 修复插件测试获取到的插件元数据主页为空时报错的问题

## [4.0.6] - 2024-11-20

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions src/providers/docker_test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from typing import Any

import docker
from pydantic import BaseModel, Field, field_validator, model_validator
from pydantic_core import PydanticCustomError
from pyjson5 import Json5DecoderException

import docker
from src.providers.constants import DOCKER_IMAGES, REGISTRY_PLUGINS_URL
from src.providers.utils import load_json

Expand All @@ -15,7 +15,7 @@ class Metadata(BaseModel):

name: str
desc: str
homepage: str
homepage: str | None = None
type: str | None = None
supported_adapters: list[str] | None = None

Expand Down
64 changes: 64 additions & 0 deletions tests/utils/docker_test/test_docker_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,67 @@ async def test_docker_plugin_test(mocked_api: MockRouter, mocker: MockerFixture)
detach=False,
remove=True,
)


async def test_docker_plugin_test_metadata_some_fields_empty(
mocked_api: MockRouter, mocker: MockerFixture
):
"""测试 metadata 的部分字段为空"""
from src.providers.docker_test import DockerPluginTest, DockerTestResult, Metadata

mocked_run = mocker.Mock()
mocked_run.return_value = json.dumps(
{
"metadata": {
"name": "name",
"desc": "desc",
"homepage": None,
"type": None,
"supported_adapters": None,
},
"outputs": ["test"],
"load": True,
"run": True,
"version": "0.0.1",
"config": "",
}
).encode()
mocked_client = mocker.Mock()
mocked_client.containers.run = mocked_run
mocked_docker = mocker.patch("docker.DockerClient")
mocked_docker.return_value = mocked_client

test = DockerPluginTest("project_link", "module_name")
result = await test.run("3.12")

assert result == snapshot(
DockerTestResult(
config="",
load=True,
metadata=Metadata(
desc="desc",
homepage=None,
name="name",
supported_adapters=None,
type=None,
),
outputs=["test"],
run=True,
test_env="python==3.12",
version="0.0.1",
)
)

assert not mocked_api["store_plugins"].called
mocked_run.assert_called_once_with(
"ghcr.io/nonebot/nonetest:3.12-latest",
environment=snapshot(
{
"PLUGIN_INFO": "project_link:module_name",
"PLUGIN_CONFIG": "",
"PLUGINS_URL": "https://raw.githubusercontent.com/nonebot/registry/results/plugins.json",
}
),
detach=False,
remove=True,
)

0 comments on commit adaed7f

Please sign in to comment.