|
| 1 | +# 测试验证指南 |
| 2 | + |
| 3 | +## 🎯 问题分析 |
| 4 | + |
| 5 | +### 原始脚本的问题 |
| 6 | + |
| 7 | +`run-all-tests.sh` 只检查 `metadata ingest` 的退出码: |
| 8 | + |
| 9 | +```bash |
| 10 | +if metadata ingest -c "$REL_PATH" > /tmp/test_output_$$.log 2>&1; then |
| 11 | + echo "✓ Test completed successfully" # ← 只要没报错就算成功 |
| 12 | +``` |
| 13 | +
|
| 14 | +**问题**:即使owner配置错误(继承失败、多owner丢失),只要ingestion运行完成,就显示"成功"。 |
| 15 | +
|
| 16 | +### 为什么会这样? |
| 17 | +
|
| 18 | +`metadata ingest` 命令在以下情况下**不会**返回错误码: |
| 19 | +1. Owner查找失败(只打印WARNING) |
| 20 | +2. Owner继承不工作(静默失败) |
| 21 | +3. 多owner只保留了一个(没有验证机制) |
| 22 | +4. Owner配置被忽略(使用了default) |
| 23 | +
|
| 24 | +## ✅ 解决方案 |
| 25 | +
|
| 26 | +### 方案1: 使用增强版脚本(推荐) |
| 27 | +
|
| 28 | +新脚本 `run-all-tests-with-validation.sh` 会: |
| 29 | +1. 运行 ingestion |
| 30 | +2. **调用 API 验证实际结果** |
| 31 | +3. 检查 owner 数量和名称 |
| 32 | +
|
| 33 | +#### 使用方法 |
| 34 | +
|
| 35 | +```bash |
| 36 | +cd ~/workspaces/OpenMetadata/ingestion/tests/unit/metadata/ingestion/owner_config_tests |
| 37 | + |
| 38 | +# 运行带验证的脚本 |
| 39 | +./run-all-tests-with-validation.sh |
| 40 | +``` |
| 41 | +
|
| 42 | +#### 添加验证规则 |
| 43 | +
|
| 44 | +编辑脚本中的 `TEST_VALIDATIONS` 数组: |
| 45 | +
|
| 46 | +```bash |
| 47 | +# 格式: "测试文件"="service_name:entity_type:entity_name:expected_count:..." |
| 48 | +TEST_VALIDATIONS["test-03-multiple-users.yaml"]="postgres-test-03-multiple-users:databaseSchemas:finance_db.accounting:2" |
| 49 | +``` |
| 50 | +
|
| 51 | +**示例**: |
| 52 | +```bash |
| 53 | +# Test 3: 验证 accounting schema 有2个owners |
| 54 | +TEST_VALIDATIONS["test-03-multiple-users.yaml"]="postgres-test-03-multiple-users:databaseSchemas:finance_db.accounting:2" |
| 55 | + |
| 56 | +# Test 5: 验证继承(schema和table都应该有finance-team) |
| 57 | +TEST_VALIDATIONS["test-05-inheritance-enabled.yaml"]="postgres-test-05-inheritance-on:databaseSchemas:finance_db.accounting:1:tables:finance_db.accounting.revenue:1" |
| 58 | + |
| 59 | +# Test 8: 验证多个实体 |
| 60 | +TEST_VALIDATIONS["test-08-complex-mixed.yaml"]="postgres-test-08-complex:databaseSchemas:finance_db.accounting:2:tables:finance_db.accounting.revenue:3" |
| 61 | +``` |
| 62 | +
|
| 63 | +--- |
| 64 | +
|
| 65 | +### 方案2: 修改原始脚本 |
| 66 | +
|
| 67 | +如果要修改 `run-all-tests.sh`,添加日志检查: |
| 68 | +
|
| 69 | +```bash |
| 70 | +# 在第79行后添加 |
| 71 | +if metadata ingest -c "$REL_PATH" > /tmp/test_output_$$.log 2>&1; then |
| 72 | + # 检查日志中的WARNING |
| 73 | + WARNING_COUNT=$(grep -c "Could not find owner\|VALIDATION ERROR" /tmp/test_output_$$.log || true) |
| 74 | + |
| 75 | + if [ $WARNING_COUNT -gt 0 ]; then |
| 76 | + echo -e " ${YELLOW}⚠${NC} Test completed with $WARNING_COUNT warnings" |
| 77 | + echo -e "${YELLOW} Check validation warnings:${NC}" |
| 78 | + grep "Could not find owner\|VALIDATION ERROR" /tmp/test_output_$$.log | head -3 | sed 's/^/ /' |
| 79 | + else |
| 80 | + echo -e " ${GREEN}✓${NC} Test completed successfully" |
| 81 | + fi |
| 82 | + ((PASSED++)) |
| 83 | +else |
| 84 | + # ... 错误处理 |
| 85 | +fi |
| 86 | +``` |
| 87 | +
|
| 88 | +--- |
| 89 | +
|
| 90 | +### 方案3: 手动验证 |
| 91 | +
|
| 92 | +运行测试后,手动检查结果: |
| 93 | +
|
| 94 | +```bash |
| 95 | +# 设置环境变量 |
| 96 | +export JWT_TOKEN="your_token" |
| 97 | + |
| 98 | +# 验证 Test 3 - accounting schema 应该有2个owners |
| 99 | +curl -s "http://localhost:8585/api/v1/databaseSchemas/name/postgres-test-03-multiple-users.finance_db.accounting" \ |
| 100 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners | length' |
| 101 | + |
| 102 | +# 期望输出: 2 |
| 103 | + |
| 104 | +# 验证 Test 5 - accounting schema 应该继承 finance-team |
| 105 | +curl -s "http://localhost:8585/api/v1/databaseSchemas/name/postgres-test-05-inheritance-on.finance_db.accounting" \ |
| 106 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 107 | + |
| 108 | +# 期望输出: "finance-team"(不是 "data-platform-team") |
| 109 | +``` |
| 110 | +
|
| 111 | +--- |
| 112 | +
|
| 113 | +## 📊 完整验证清单 |
| 114 | +
|
| 115 | +### Test 1: Basic Configuration |
| 116 | +```bash |
| 117 | +# finance_db → data-platform-team |
| 118 | +curl -s "$API/v1/databases/name/postgres-test-01-basic.finance_db" \ |
| 119 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 120 | +# 期望: "data-platform-team" |
| 121 | +``` |
| 122 | +
|
| 123 | +### Test 2: FQN Matching |
| 124 | +```bash |
| 125 | +# treasury schema → treasury-team (FQN match) |
| 126 | +curl -s "$API/v1/databaseSchemas/name/postgres-test-02-fqn.finance_db.treasury" \ |
| 127 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 128 | +# 期望: "treasury-team" |
| 129 | +``` |
| 130 | +
|
| 131 | +### Test 3: Multiple Users ⭐ |
| 132 | +```bash |
| 133 | +# accounting schema → ["alice", "bob"] (2个owners) |
| 134 | +curl -s "$API/v1/databaseSchemas/name/postgres-test-03-multiple-users.finance_db.accounting" \ |
| 135 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners | length' |
| 136 | +# 期望: 2 |
| 137 | + |
| 138 | +curl -s "$API/v1/databaseSchemas/name/postgres-test-03-multiple-users.finance_db.accounting" \ |
| 139 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 140 | +# 期望: "alice", "bob" |
| 141 | +``` |
| 142 | +
|
| 143 | +### Test 5: Inheritance Enabled ⭐ |
| 144 | +```bash |
| 145 | +# accounting schema → "finance-team" (继承自database) |
| 146 | +curl -s "$API/v1/databaseSchemas/name/postgres-test-05-inheritance-on.finance_db.accounting" \ |
| 147 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 148 | +# 期望: "finance-team"(不是 "data-platform-team") |
| 149 | + |
| 150 | +# revenue table → "finance-team" (继承自schema) |
| 151 | +curl -s "$API/v1/tables/name/postgres-test-05-inheritance-on.finance_db.accounting.revenue" \ |
| 152 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners[].name' |
| 153 | +# 期望: "finance-team" |
| 154 | +``` |
| 155 | +
|
| 156 | +### Test 8: Complex Mixed |
| 157 | +```bash |
| 158 | +# accounting schema → ["alice", "bob"] |
| 159 | +curl -s "$API/v1/databaseSchemas/name/postgres-test-08-complex.finance_db.accounting" \ |
| 160 | + -H "Authorization: Bearer $JWT_TOKEN" | jq '.owners | length' |
| 161 | +# 期望: 2 |
| 162 | +``` |
| 163 | +
|
| 164 | +--- |
| 165 | +
|
| 166 | +## 🔧 创建自动验证脚本 |
| 167 | +
|
| 168 | +创建一个简单的验证脚本: |
| 169 | +
|
| 170 | +```bash |
| 171 | +#!/bin/bash |
| 172 | +# verify-test-results.sh |
| 173 | + |
| 174 | +API="http://localhost:8585/api" |
| 175 | +TOKEN="${JWT_TOKEN:-default_token}" |
| 176 | + |
| 177 | +echo "验证 Test 3: Multiple Users" |
| 178 | +COUNT=$(curl -s "$API/v1/databaseSchemas/name/postgres-test-03-multiple-users.finance_db.accounting" \ |
| 179 | + -H "Authorization: Bearer $TOKEN" | jq '.owners | length') |
| 180 | + |
| 181 | +if [ "$COUNT" -eq 2 ]; then |
| 182 | + echo "✅ Test 3: accounting schema 有2个owners" |
| 183 | +else |
| 184 | + echo "❌ Test 3: 期望2个owners,实际$COUNT个" |
| 185 | +fi |
| 186 | + |
| 187 | +echo "" |
| 188 | +echo "验证 Test 5: Inheritance" |
| 189 | +OWNER=$(curl -s "$API/v1/databaseSchemas/name/postgres-test-05-inheritance-on.finance_db.accounting" \ |
| 190 | + -H "Authorization: Bearer $TOKEN" | jq -r '.owners[0].name') |
| 191 | + |
| 192 | +if [ "$OWNER" = "finance-team" ]; then |
| 193 | + echo "✅ Test 5: 继承正常工作" |
| 194 | +else |
| 195 | + echo "❌ Test 5: 期望finance-team,实际$OWNER" |
| 196 | +fi |
| 197 | +``` |
| 198 | +
|
| 199 | +--- |
| 200 | +
|
| 201 | +## 🎯 推荐做法 |
| 202 | +
|
| 203 | +1. **使用增强版脚本**: |
| 204 | + ```bash |
| 205 | + ./run-all-tests-with-validation.sh |
| 206 | + ``` |
| 207 | +
|
| 208 | +2. **为关键测试添加验证规则**: |
| 209 | + - Test 3: 多owner |
| 210 | + - Test 5: 继承 |
| 211 | + - Test 8: 复杂场景 |
| 212 | +
|
| 213 | +3. **手动验证重要测试**: |
| 214 | + ```bash |
| 215 | + # 运行测试后 |
| 216 | + ./verify-test-results.sh |
| 217 | + ``` |
| 218 | +
|
| 219 | +4. **查看日志中的WARNING**: |
| 220 | + ```bash |
| 221 | + metadata ingest -c test-03.yaml 2>&1 | grep -i "warning\|error\|validation" |
| 222 | + ``` |
| 223 | +
|
| 224 | +这样才能确保测试真正成功! |
0 commit comments