集成测试¶
(要使用 docker compose 堆栈运行集成测试,请查看 运行集成测试)
GitHub Actions¶
用于集成测试的 GitHub Actions 脚本都定义在 /dev/oci_env_integration/actions
下。这些都是 python 文件,它们使用 action_lib.py
库来启动 oci-env 环境并在其上运行测试。
示例脚本
import action_lib
env = action_lib.OCIEnvIntegrationTest(
envs=[
{
"env_file": "standalone.compose.env",
"run_tests": True,
"db_restore": None,
"pytest_flags": '-m sync'
},
{
"env_file": "sync-test.compose.env",
"run_tests": False,
"db_restore": "insights-fixture",
"pytest_flags": None
}
]
)
action_lib
提供了 OCIEnvIntegrationTest 类,该类接收一个用于运行测试的环境列表。环境配置如下:
envs: list of environment definitions to spin up for testing. Environment
definitions accept the following args:
env_file (string, required): oci-env env file to use for the tests. These are all loaded
from dev/oci_env_integration/oci_env_configs
run_tests (boolean, required): if true, integration tests will be run inside this instance
db_restore (string, optional): database backup to restore before running tests These are all
loaded from dev/oci_env_integration/oci_env_configs. When defining this, omit
the file extension (ex: fixture, not fixtur.tar.gz)
pytest_flags (string, optional): flags to pass to pytest when running integration tests.
oci-env automatically identifies which pytest marks to apply to tests based
on the environment that's running, however in some cases you may want to
override this if the test is meant to only apply to a subset of tests (such as rbac)
wait_before_tests (int, optional): some environments need some extra time set-up configs
that oci-env poll can't monitor. This will cause the environment to wait the given
number of seconds before running integration tests after the stack has spun up.
要设置新的 GitHub Action
-
在
actions/
目录中创建一个新脚本 -
为其定义一个 Makefile 命令,如下所示
.PHONY: gh-action/certified-sync
gh-action/certified-sync:
python3 dev/oci_env_integration/actions/certified-sync.py
- 将新的 action 添加到
/.github/workflows/ci_oci-env-integration.yml
,如下所示
jobs:
integration:
strategy:
fail-fast: false
matrix:
env:
- TEST_PROFILE: ldap
- TEST_PROFILE: keycloak
- TEST_PROFILE: standalone
- TEST_PROFILE: rbac
- TEST_PROFILE: certified-sync <-----------------------
- TEST_PROFILE: insights
- TEST_PROFILE: iqe_rbac
- TEST_PROFILE: x_repo_search
标记¶
测试通常针对三种潜在的部署模式之一编写
- 云/洞察模式
- 社区
- 独立
要使测试在这些类别之一中运行,您可以在测试中包含 deployment_cloud
、deployment_community
或 deployment_standalone
标记。
旨在在任何部署模式下通过的测试应标记为 all
。默认情况下,未标记的测试将收到 all
标记`。
所有 deployment_standalone
测试也应在使用 ldap 或 keycloak 身份验证运行时通过。如果测试旨在测试特定的身份验证后端,请使用 ldap
或 keycloak
标记,并删除 deployment_standalone
。
集成测试配置¶
集成测试使用环境变量进行配置。这些变量在 oci-env 配置文件中设置,以便您正在运行的配置文件的集成测试应该可以开箱即用。以下是基本配置文件使用的设置示例
# Integration test settings
HUB_API_ROOT={API_PROTOCOL}://{API_HOST}:{API_PORT}/api/galaxy/
CONTAINER_REGISTRY={API_HOST}:{API_PORT}
HUB_LOCAL=1
HUB_USE_MOVE_ENDPOINT=true
HUB_TEST_AUTHENTICATION_BACKEND=galaxy
HUB_TEST_MARKS=deployment_standalone or all