Loading...
Loading...
Compare original and translation side by side
percli plugin test-schemasschemas/<type>/<name>/<name>.jsonpackage modelpackage modelpercli plugin test-schemaslocalhostpercli plugin test-schemasschemas/<type>/<name>/<name>.jsonpackage modelpackage modelpercli plugin test-schemaslocalhostclose({...})close()close({...})close()percli plugin test-schemas@perses-dev/plugin-systempercli plugin startpercli plugin test-schemas@perses-dev/plugin-systempercli plugin startpackage modelclose({...})schemas/<type>/<name>/<name>.jsonpercli plugin test-schemaspackage modelclose({...})schemas/<type>/<name>/<name>.jsonpercli plugin test-schemas@perses-dev/plugin-systemuseDataQueriesuseTimeRangenpm test -- --watchAll=false@perses-dev/plugin-systemuseDataQueriesuseTimeRangenpm test -- --watchAll=falsedocker run --name perses-test -d -p 127.0.0.1:8080:8080 persesdev/persespercli plugin startdocker run --name perses-test -d -p 127.0.0.1:8080:8080 persesdev/persespercli plugin startmigrate/migrate.cuepercli migrate --input grafana-dashboard.json --output perses-dashboard.jsonmigrate/migrate.cuepercli migrate --input grafana-dashboard.json --output perses-dashboard.json| Error | Cause | Solution |
|---|---|---|
| CUE file missing | Add |
| Unclosed | Count opening/closing braces; ensure every |
| Wrong CUE import path (e.g., using Go-style paths instead of CUE module paths) | Check |
| JSON example contains fields not defined in the CUE schema | Either add the field to the CUE schema or remove it from the JSON example; |
| React test: "Cannot find module '@perses-dev/plugin-system'" | Missing mock setup for the plugin system dependency | Add |
| React test: "Invalid hook call" | Using wrong test renderer or missing React context providers | Wrap component in |
| Integration test: connection refused on port 8080 | Local Perses server not running or bound to a different port | Start server with |
| Integration test: 401 Unauthorized | Perses server has auth enabled but test is not authenticating | Run |
| Migration test: unexpected panel type | Grafana dashboard JSON contains panel types not handled by | Add a migration case for the new panel type in |
| Migration test: schema version mismatch | Grafana JSON structure changed between versions (e.g., v8 vs v10 panel format) | Check the Grafana version in the test fixture and ensure |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| CUE文件顶部缺失 | 在每个CUE schema文件的首行添加 |
| CUE中存在未闭合的 | 统计开闭大括号数量;确保每个 |
| CUE导入路径错误(如使用Go风格路径而非CUE模块路径) | 检查 |
| JSON示例包含CUE schema中未定义的字段 | 要么将该字段添加到CUE schema中,要么从JSON示例中删除; |
| React测试:"Cannot find module '@perses-dev/plugin-system'" | 缺失插件系统依赖的模拟配置 | 添加 |
| React测试:"Invalid hook call" | 使用了错误的测试渲染器或缺失React上下文提供者 | 在测试期间将组件包裹在 |
| 集成测试:端口8080连接被拒绝 | 本地Perses服务器未运行或绑定到其他端口 | 使用 |
| 集成测试:401 Unauthorized | Perses服务器已启用认证,但测试未进行身份验证 | 测试前运行 |
| 迁移测试:出现意外面板类型 | Grafana仪表盘JSON包含 | 在 |
| 迁移测试:schema版本不匹配 | Grafana JSON结构在不同版本间发生变化(如v8与v10的面板格式) | 检查测试用例中的Grafana版本,并确保 |
| Anti-Pattern | Why It Fails | Do Instead |
|---|---|---|
| Running component tests before schema tests pass | Components depend on valid schemas; testing components against broken schemas produces misleading failures | Always run |
| Testing against a shared or production Perses server | Tests may corrupt real data, hit rate limits, or fail due to network latency; results are non-reproducible | Always use a local Perses instance via Docker or binary — disposable and isolated |
| JSON examples that only test the happy path | Schemas with optional fields, unions, or conditional logic have branches that never get exercised | Create multiple JSON examples per schema: minimal (required fields only), full (all fields), and edge cases (empty arrays, null values) |
| Skipping migration tests because "the schema didn't change" | Upstream Grafana panel JSON evolves independently; a working migration can break without any local changes | Run migration tests against current Grafana sample fixtures on every test cycle |
| Mocking the entire plugin-system module with empty stubs | Tests pass but don't verify that hooks are called correctly or return expected shapes | Mock individual hooks with realistic return values (e.g., |
| 反模式 | 失败原因 | 正确做法 |
|---|---|---|
| 在schema测试通过前运行组件测试 | 组件依赖有效的schema;针对损坏的schema测试组件会产生误导性的失败结果 | 始终优先运行 |
| 针对共享或生产环境的Perses服务器进行测试 | 测试可能损坏真实数据、触发速率限制,或因网络延迟失败;测试结果不可复现 | 始终通过Docker或二进制文件使用本地Perses实例——可随时销毁且环境隔离 |
| JSON示例仅测试正常路径 | 包含可选字段、联合类型或条件逻辑的schema存在从未被测试过的分支 | 为每个schema创建多个JSON示例:极简版(仅必填字段)、完整版(所有字段)和边缘案例(空数组、空值) |
| 因「schema未变更」而跳过迁移测试 | 上游Grafana面板JSON会独立演化;即使本地无变更,原本正常的迁移也可能失效 | 在每次测试周期中,针对当前Grafana示例用例运行迁移测试 |
| 使用空存根模拟整个plugin-system模块 | 测试可通过,但无法验证钩子是否被正确调用或返回预期格式 | 为单个钩子模拟真实的返回值(如 |
| Rationalization | Reality | Required Action |
|---|---|---|
| "Schema tests pass so the plugin works" | Schema tests only validate CUE syntax and JSON conformance — they say nothing about whether the React component renders | Run all four phases |
| "I tested with one JSON example and it passed" | One example may only exercise the default branch of a union type; other branches remain untested | Create JSON examples for every schema variant |
| "Integration tests are slow, I'll skip them this time" | Integration tests catch issues that unit tests cannot: plugin registration, data binding, render lifecycle | Always run integration tests against local Perses |
| "The migration worked for my Grafana dashboard" | Your dashboard may only use a subset of panel types; other users' dashboards will have panels you didn't test | Test migration with diverse Grafana fixtures covering all supported panel types |
| 错误合理化 | 实际情况 | 必要操作 |
|---|---|---|
| 「Schema测试通过,所以插件可正常工作」 | Schema测试仅验证CUE语法和JSON一致性——无法说明React组件可正常渲染 | 运行全部四个阶段的测试 |
| 「我用一个JSON示例测试过了,没问题」 | 单个示例可能仅测试了联合类型的默认分支;其他分支仍未被测试 | 为每个schema变体创建JSON示例 |
| 「集成测试太慢了,这次我跳过」 | 集成测试可捕捉单元测试无法发现的问题:插件注册、数据绑定、渲染生命周期 | 始终针对本地Perses运行集成测试 |
| 「我的Grafana仪表盘迁移成功了,没问题」 | 你的仪表盘可能仅使用了部分面板类型;其他用户的仪表盘可能包含你未测试的面板 | 使用涵盖所有支持面板类型的多样化Grafana用例测试迁移 |
package modelperclipercli plugin test-schemaspackage modelperclipercli plugin test-schemasperclitest-schemasmigrate/migrate.cuepercliperclitest-schemasmigrate/migrate.cue