charmkeeper-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlan:
- Find the unit tests in the repository (their could be multiple "tests/unit" folders).
- Ensure each set of unit tests is following the implementation standards.
- Run the tests to ensure the code work as expected.
计划:
- 在代码仓库中查找单元测试(可能存在多个"tests/unit"文件夹)。
- 确保每一组单元测试都符合实现标准。
- 运行测试以确保代码按预期工作。
Implementation standards
实现标准
-
Unit test should be implemented with, not
ops.testing.harness -
Lint produced code with.
tox -e lint
-
单元测试应使用实现,而非
ops.testing。harness -
使用对生成的代码进行代码检查。
tox -e lint
Testing
测试
Writing unit tests
编写单元测试
-
Unit test must be implemented with:
ops.testing- See How to migrate unit tests from Harness if the charm is currently using harness.
-
For each charm in the repository, there should be afolder like: https://github.com/canonical/platform-engineering-charm-template/tree/main/tests
tests/- Unit tests goes in
tests/unit - Fixtures should look like the ones in https://raw.githubusercontent.com/canonical/haproxy-operator/refs/heads/main/haproxy-operator/tests/unit/conftest.py
- Helper functions should go in . See an example here: https://raw.githubusercontent.com/canonical/haproxy-operator/refs/heads/main/haproxy-operator/tests/unit/helper.py
tests/unit/helper.py - There is a to test the basic behaviors of the charm.
tests/unit/test_charm.py - There should be additional files to test specific integrations of the charm (see https://github.com/canonical/haproxy-operator/tree/main/haproxy-operator/tests/unit)
tests/unit/test_xxx.py
- Unit tests goes in
-
单元测试必须使用实现:
ops.testing- 如果当前charm使用的是harness,请查看如何从Harness迁移单元测试。
-
对于代码仓库中的每个charm,都应有一个文件夹,示例可参考:https://github.com/canonical/platform-engineering-charm-template/tree/main/tests
tests/- 单元测试应放在目录下
tests/unit - 测试夹具(Fixtures)应参考此示例:https://raw.githubusercontent.com/canonical/haproxy-operator/refs/heads/main/haproxy-operator/tests/unit/conftest.py
- 辅助函数应放在中,示例可参考:https://raw.githubusercontent.com/canonical/haproxy-operator/refs/heads/main/haproxy-operator/tests/unit/helper.py
tests/unit/helper.py - 应有一个文件用于测试charm的基本行为。
tests/unit/test_charm.py - 还应有额外的文件用于测试charm的特定集成(示例可参考:https://github.com/canonical/haproxy-operator/tree/main/haproxy-operator/tests/unit)
tests/unit/test_xxx.py
- 单元测试应放在
Local testing
本地测试
The unit tests should be run in a virtual machine named "charmkeeper".
If the machine doesn't exist, create it with: .
scripts/create-charmkeeper-vm.shIf not already done, mount the working directory folder in the machine with
bash
multipass mount --type native $PWD charmkeeper:/workdirLook at CONTRIBUTING.md to see if there are specific instructions to test the charm.
Unless there is something specific mentioned, you should be able to run the tests with:
bash
multipass exec charmkeeper -d /workdir/ -- tox 单元测试应在名为"charmkeeper"的虚拟机中运行。
如果该虚拟机不存在,请使用以下命令创建:。
scripts/create-charmkeeper-vm.sh如果尚未挂载工作目录,请使用以下命令将工作目录挂载到虚拟机中:
bash
multipass mount --type native $PWD charmkeeper:/workdir查看CONTRIBUTING.md文件,确认是否有测试该charm的特定说明。
除非有特别说明,否则你可以使用以下命令运行测试:
bash
multipass exec charmkeeper -d /workdir/ -- tox